Response class
An HTTP response where the entire response body is known in advance.
class Response extends BaseResponse {
/// The bytes comprising the body of this response.
final Uint8List bodyBytes;
/// The body of the response as a string. This is converted from [bodyBytes]
/// using the `charset` parameter of the `Content-Type` header field, if
/// available. If it's unavailable or if the encoding name is unknown,
/// [Encoding.ISO_8859_1] is used by default, as per [RFC 2616][].
///
/// [RFC 2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
String get body => decodeString(bodyBytes, _encodingForHeaders(headers));
/// Creates a new HTTP response with a string body.
Response(
String body,
int statusCode,
{BaseRequest request,
Map<String, String> headers: const {},
bool isRedirect: false,
bool persistentConnection: true,
String reasonPhrase})
: this.bytes(
encodeString(body, _encodingForHeaders(headers)),
statusCode,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
/// Create a new HTTP response with a byte array body.
Response.bytes(
List<int> bodyBytes,
int statusCode,
{BaseRequest request,
Map<String, String> headers: const {},
bool isRedirect: false,
bool persistentConnection: true,
String reasonPhrase})
: bodyBytes = toUint8List(bodyBytes),
super(
statusCode,
bodyBytes.length,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
/// Creates a new HTTP response by waiting for the full body to become
/// available from a [StreamedResponse].
static Future<Response> fromStream(StreamedResponse response) {
return response.stream.toBytes().then((body) {
return new Response.bytes(
body,
response.statusCode,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
});
}
}
Extends
BaseResponse > Response
Static Methods
Future<Response> fromStream(StreamedResponse response) #
Creates a new HTTP response by waiting for the full body to become available from a StreamedResponse.
static Future<Response> fromStream(StreamedResponse response) {
return response.stream.toBytes().then((body) {
return new Response.bytes(
body,
response.statusCode,
request: response.request,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
});
}
Constructors
new Response(String body, int statusCode, {BaseRequest request, Map<String, String> headers: const{}, bool isRedirect: false, bool persistentConnection: true, String reasonPhrase}) #
Creates a new HTTP response with a string body.
Response(
String body,
int statusCode,
{BaseRequest request,
Map<String, String> headers: const {},
bool isRedirect: false,
bool persistentConnection: true,
String reasonPhrase})
: this.bytes(
encodeString(body, _encodingForHeaders(headers)),
statusCode,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
new Response.bytes(List<int> bodyBytes, int statusCode, {BaseRequest request, Map<String, String> headers: const{}, bool isRedirect: false, bool persistentConnection: true, String reasonPhrase}) #
Create a new HTTP response with a byte array body.
Response.bytes(
List<int> bodyBytes,
int statusCode,
{BaseRequest request,
Map<String, String> headers: const {},
bool isRedirect: false,
bool persistentConnection: true,
String reasonPhrase})
: bodyBytes = toUint8List(bodyBytes),
super(
statusCode,
bodyBytes.length,
request: request,
headers: headers,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
Properties
final String body #
The body of the response as a string. This is converted from bodyBytes
using the charset parameter of the Content-Type header field, if
available. If it's unavailable or if the encoding name is unknown,
[Encoding.ISO_8859_1] is used by default, as per RFC 2616.
String get body => decodeString(bodyBytes, _encodingForHeaders(headers));
final Uint8List bodyBytes #
The bytes comprising the body of this response.
final Uint8List bodyBytes
final int contentLength #
The size of the response body, in bytes. If the size of the request is not known in advance, this is -1.
final int contentLength
final Map<String, String> headers #
The headers for this response.
final Map<String, String> headers
final bool isRedirect #
Whether this response is a redirect.
final bool isRedirect
final bool persistentConnection #
Whether the server requested that a persistent connection be maintained.
final bool persistentConnection
final String reasonPhrase #
The reason phrase associated with the status code.
final String reasonPhrase
final BaseRequest request #
The (frozen) request that triggered this response.
final BaseRequest request
final int statusCode #
The status code of the response.
final int statusCode