Skip to content

Adding back missing Request and Response fields #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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