MockHttpResponse class
Mock implementation of HttpResponse for testing.
Captures all written data for assertions.
Example:
final response = MockHttpResponse();
// ... run handler ...
expect(response.statusCode, 200);
expect(response.body, contains('success'));
- Implemented types
Constructors
Properties
- body → String
-
Written body decoded as UTF-8 string.
no setter
-
bodyBytes
→ List<
int> -
All written bytes.
no setter
- bodyJson → dynamic
-
Written body parsed as JSON.
no setter
- bufferOutput ↔ bool
-
Gets or sets if the HttpResponse should buffer output.
getter/setter pairoverride
- connectionInfo → HttpConnectionInfo?
-
Gets information about the client connection. Returns
nullif the socket is not available.no setteroverride - contentLength ↔ int
-
Gets and sets the content length of the response. If the size of
the response is not known in advance set the content length to
-1, which is also the default if not set.
getter/setter pairoverride
-
Cookies to set in the client (in the 'set-cookie' header).
no setteroverride
- deadline ↔ Duration?
-
Set and get the deadline for the response. The deadline is timed from the
time it's set. Setting a new deadline will override any previous deadline.
When a deadline is exceeded, the response will be closed and any further
data ignored.
getter/setter pairoverride
-
done
→ Future<
void> -
Future that completes when close is called.
no setteroverride
- encoding ↔ Encoding
-
The Encoding used when writing strings.
getter/setter pairoverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- headers → MockHttpHeaders
-
Returns the response headers.
final
- isClosed → bool
-
Whether the response has been closed.
no setter
- persistentConnection ↔ bool
-
Gets and sets the persistent connection state. The initial value
of this property is the persistent connection state from the
request.
getter/setter pairoverride
- reasonPhrase ↔ String
-
The reason phrase for the response.
getter/setter pairoverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- statusCode ↔ int
-
The status code of the response.
getter/setter pairoverride
Methods
-
add(
List< int> data) → void -
Adds byte
datato the target consumer, ignoring encoding.override -
addError(
Object error, [StackTrace? stackTrace]) → void -
Passes the error to the target consumer as an error event.
override
-
addStream(
Stream< List< stream) → Futureint> > -
Adds all elements of the given
stream.override -
close(
) → Future -
Close the target consumer.
override
-
detachSocket(
{bool writeHeaders = true}) → Future< Socket> -
Detaches the underlying socket from the HTTP server. When the
socket is detached the HTTP server will no longer perform any
operations on it.
override
-
flush(
) → Future< void> -
Returns a Future that completes once all buffered data is accepted by the
underlying StreamConsumer.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
override
-
redirect(
Uri location, {int status = HttpStatus.movedTemporarily}) → Future -
Respond with a redirect to
location.override -
toString(
) → String -
A string representation of this object.
inherited
-
write(
Object? object) → void -
Converts
objectto a String by invoking Object.toString and adds the encoding of the result to the target consumer.override -
writeAll(
Iterable objects, [String separator = '']) → void -
Iterates over the given
objectsand writes them in sequence.override -
writeCharCode(
int charCode) → void -
Writes the character of
charCode.override -
writeln(
[Object? object = '']) → void -
Converts
objectto a String by invoking Object.toString and writes the result tothis, followed by a newline.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited