SimulatedResponse class

Response returned by simulations.

The Server.simulate method returns an instance of this class.

This class extends Response with methods to retrieve the body of the HTTP response. The other response classes (used by request handlers to produce HTTP responses) only allow the body to be produced.

Body

The body of the simulated response can be retrieved as a sequence of bytes using bodyBytes, or as a String using either bodyStr or bodyString.

The Handler that produced the response could have provided the body as a sequence of bytes, a String, or not provided any body at all. The simulated response internally stores any body in its source format.

The retrieval methods encode/decode the source into the desired format, if needed. If the source was a String, then bodyString does not perform any encoding; but bodyBytes will require encoding the string value into bytes. If the source was a sequence of bytes, then bodyBytes does not perform any decoding; but retrieving it with bodyString will require decoding those bytes into a String. The bodyStr getter is a convenience method for invoking bodyString with the UTF-8 encoding.

The bodyIsEmpty getter indicates if the body has content or not. This is more efficient than retrieving the body and then checking if it is empty or not, since no encoding/decoding will be performed.

The source format of the body can be determined from the bodyType.

Inheritance

Constructors

SimulatedResponse(_CoreResponseSimulated core, String sessionCookieName)
Constructor

Properties

bodyIsEmpty bool
Indicates if there is a body has content or not.
no setter
bodyStr String
Retrieves the body as a String.
no setter
bodyType SimulatedResponseBodyType
The source format of the body.
no setter
contentType ContentType?
Content-type of the response.
getter/setter pairinherited
cookies List<Cookie>
Cookies in the response.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
session Session?
Gets the session.
getter/setter pairinherited
sessionId String?
Identification of the session.
getter/setter pair
status int
HTTP status code.
getter/setter pairinherited

Methods

bodyBytes(Encoding encoding) List<int>
Retrieves the body as a sequence of bytes.
bodyString(Encoding encoding) String
Retrieves the body as a String.
cookieAdd(Cookie cookie) → void
Set a cookie.
inherited
cookieDelete(String name, [String? path, String? domain]) → void
Delete a cookie.
inherited
finish(Request req) Future
Method that is invoked at the end of creating the HTTP response.
inherited
headerAdd(String name, String value) → void
Adds a HTTP header
inherited
headerAddDate(String name, DateTime date) → void
Adds a HTTP header containing a RFC1123 formatted date.
inherited
headerExists(String name) bool
Whether a header has been set or not.
inherited
headerNames() Iterable<String>
Header names
inherited
headerRemove(String name, [String? value]) bool
Removes named header
inherited
headerRemoveAll() → void
Remove all headers.
inherited
headerSet(String name, String value) → void
Sets a HTTP header
inherited
headerValues(String name) Iterable<String>?
Header values
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited