Response class final
An HTTP response returned by Oxy.
A response owns status metadata, headers, and an optional ResponseBody. Response instances are immutable; use copyWith or buffered when a middleware needs to derive a modified response.
Response bodies can be replayable or one-shot. Convenience readers such as text, json, and bytes consume the body stream.
Constructors
- Response(Object? body, {int status = 200, String statusText = 'OK', HeadersInit? headers, Uri? url, bool redirected = false, bool fromCache = false})
-
Response.bytes(List<
int> bytes, {int status = 200, String statusText = 'OK', HeadersInit? headers, Uri? url, bool redirected = false, bool fromCache = false}) -
Creates a replayable response from raw
bytes. - Response.json(Object? value, {int status = 200, String statusText = 'OK', HeadersInit? headers, Uri? url, bool redirected = false, bool fromCache = false})
- Creates a replayable JSON response.
-
Response.stream(Stream<
List< stream, {int status = 200, String statusText = 'OK', HeadersInit? headers, Uri? url, bool redirected = false, bool fromCache = false, int? contentLength})int> > - Creates a one-shot streaming response.
- Response.text(String text, {int status = 200, String statusText = 'OK', HeadersInit? headers, Uri? url, bool redirected = false, bool fromCache = false})
- Creates a replayable UTF-8 text response.
Properties
- body → ResponseBody?
-
The optional response body.
final
- fromCache → bool
-
Whether the response was served by
CacheMiddleware.final - hashCode → int
-
The hash code for this object.
no setterinherited
- headers → Headers
-
The response headers.
final
- ok → bool
-
Whether status is in the 2xx range.
no setter
- redirected → bool
-
Whether the response followed at least one redirect.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- status → int
-
The HTTP status code.
final
- statusText → String
-
The HTTP status reason phrase.
final
- url → Uri
-
The final response URL, when known.
final
Methods
-
buffered(
{int? maxBytes = 1024 * 1024}) → Future< Response> - Returns a replayable response by buffering the body into memory.
-
bytes(
{int? maxBytes}) → Future< List< int> > - Reads the response body as bytes.
-
copyWith(
{Object? body, bool clearBody = false, int? status, String? statusText, HeadersInit? headers, Uri? url, bool? redirected, bool? fromCache}) → Response - Creates a copy with selected values replaced.
-
decode<
T> ({Decoder< T> ? decoder, int? maxBytes}) → Future<T> -
Reads JSON and maps it to
T. -
drain(
{int? maxBytes = 64 * 1024}) → Future< void> - Reads and discards the response body.
-
json<
T> ({int? maxBytes}) → Future< T> - Reads and decodes the response body as JSON.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
stream(
) → Stream< List< int> > - Opens the response body stream.
-
text(
{Encoding encoding = utf8, int? maxBytes}) → Future< String> -
Reads the response body as text using
encoding. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited