Skip to content

Commit

Permalink
Add back missing Request and Response fields (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
donny-dont authored and nex3 committed May 23, 2017
1 parent e9dbebd commit 128c0bc
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ import 'utils.dart';

/// An HTTP response where the entire response body is known in advance.
class Response extends Message {
/// The location of the requested resource.
///
/// The value takes into account any redirects that occurred during the
/// request.
final Uri finalUrl;

/// The status code of the response.
final int statusCode;

/// Creates a new HTTP response with the given [statusCode].
/// The reason phrase associated with the status code.
final String reasonPhrase;

/// Creates a new HTTP response for a resource at the [finalUrl], which can
/// be a [Uri] or a [String], with the given [statusCode].
///
/// [body] is the request body. It may be either a [String], a [List<int>], a
/// [Stream<List<int>>], or `null` to indicate no body. If it's a [String],
Expand All @@ -26,11 +36,20 @@ class Response extends Message {
///
/// Extra [context] can be used to pass information between outer middleware
/// and handlers.
Response(this.statusCode,
{body,
Response(finalUrl, int statusCode,
{String reasonPhrase,
body,
Encoding encoding,
Map<String, String> headers,
Map<String, Object> context})
: this._(getUrl(finalUrl), statusCode, reasonPhrase ?? '',
body, encoding, headers, context);

Response._(this.finalUrl, this.statusCode, this.reasonPhrase,
body,
Encoding encoding,
Map<String, String> headers,
Map<String, Object> context)
: super(body, encoding: encoding, headers: headers, context: context);

/// Creates a new [Response] by copying existing values and applying specified
Expand All @@ -55,10 +74,14 @@ class Response extends Message {
var updatedHeaders = updateMap(this.headers, headers);
var updatedContext = updateMap(this.context, context);

return new Response(this.statusCode,
body: body ?? getBody(this),
headers: updatedHeaders,
context: updatedContext);
return new Response._(
this.finalUrl,
this.statusCode,
this.reasonPhrase,
body ?? getBody(this),
this.encoding,
updatedHeaders,
updatedContext);
}

/// The date and time after which the response's data should be considered
Expand Down

0 comments on commit 128c0bc

Please sign in to comment.