HttpResponse class

HTTP status, headers and a single-consumption response body. Always consume the body or await dispose, including for unsuccessful statuses.

Available extensions

Constructors

HttpResponse({required int statusCode, required Stream<List<int>> body, HttpHeaders? headers, Uri? uri, FutureOr<void> onClose()?})
HttpResponse.bytes({required int statusCode, List<int> bytes = const [], HttpHeaders? headers, Uri? uri})
Creates a response from an immutable defensive copy of bytes.
factory

Properties

body → ResponseBodyStream
final
hashCode → int
The hash code for this object.
no setterinherited
headers → HttpHeaders
final
isSuccessful → bool
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
statusCode → int
final
uri → Uri?
final

Methods

buffer({int maxBytes = 8 * 1024 * 1024}) → Future<BufferedHttpResponse>

Available on HttpResponse, provided by the HttpResponseExtensions extension

Consumes the stream into a reusable bounded snapshot.
dispose() → Future<void>
Cancels an unread or partially read body and awaits its resource cleanup.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
readBytes({int maxBytes = 8 * 1024 * 1024}) → Future<List<int>>

Available on HttpResponse, provided by the HttpResponseExtensions extension

Consumes and releases this response, including on failure.
readJson<T>({required T decode(Object? json), int maxBytes = 8 * 1024 * 1024}) → Future<T>

Available on HttpResponse, provided by the HttpResponseExtensions extension

Parses JSON and passes it to an explicit domain decoder. Does not implicitly reject non-successful HTTP statuses.
readText({int maxBytes = 8 * 1024 * 1024}) → Future<String>

Available on HttpResponse, provided by the HttpResponseExtensions extension

Consumes UTF-8 text and releases this response.
requireSuccess() → Future<HttpResponse>

Available on HttpResponse, provided by the HttpResponseExtensions extension

Returns this response for 2xx; otherwise releases it and throws metadata.
toString() → String
A string representation of this object.
inherited
use<T>(FutureOr<T> process(HttpResponse response)) → Future<T>

Available on HttpResponse, provided by the HttpResponseExtensions extension

Releases the response when processing finishes, even if processing fails. Returned values must not depend on the response remaining open.
withBody(Stream<List<int>> stream, {FutureOr<void> onClose()?}) → HttpResponse
Wraps a body while retaining cleanup of the original response.

Operators

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