Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: pkg/shelf/lib/src/response.dart

Issue 256753004: pkg/shelf: change helper method on Request and Response (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nits Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/shelf/lib/src/response.dart
diff --git a/pkg/shelf/lib/src/response.dart b/pkg/shelf/lib/src/response.dart
index e59b0c55ef8482ebee3c0d758aa1ec496473fe2e..4a3a4db695af99b7eebfd1b1a5c650f7dc922b12 100644
--- a/pkg/shelf/lib/src/response.dart
+++ b/pkg/shelf/lib/src/response.dart
@@ -53,7 +53,7 @@ class Response extends Message {
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.ok(body, {Map<String, String> headers, Encoding encoding,
+ Response.ok(body, {Map<String, String> headers, Encoding encoding,
Map<String, Object> context})
: this(200, body: body, headers: headers, encoding: encoding,
context: context);
@@ -118,7 +118,7 @@ class Response extends Message {
/// Constructs a helper constructor for redirect responses.
Response._redirect(int statusCode, location, body,
- Map<String, String> headers, Encoding encoding,
+ Map<String, String> headers, Encoding encoding,
{ Map<String, Object> context })
: this(statusCode,
body: body,
@@ -133,7 +133,7 @@ class Response extends Message {
/// information used to determine whether the requested resource has changed
/// since the last request. It indicates that the resource has not changed and
/// the old value should be used.
- Response.notModified({Map<String, String> headers,
+ Response.notModified({Map<String, String> headers,
Map<String, Object> context})
: this(304, headers: _addHeader(
headers, 'date', formatHttpDate(new DateTime.now())),
@@ -169,7 +169,7 @@ class Response extends Message {
/// If [encoding] is passed, the "encoding" field of the Content-Type header
/// in [headers] will be set appropriately. If there is no existing
/// Content-Type header, it will be set to "application/octet-stream".
- Response.notFound(body, {Map<String, String> headers, Encoding encoding,
+ Response.notFound(body, {Map<String, String> headers, Encoding encoding,
Map<String, Object> context})
: this(404, body: body, headers: headers,
context: context);
@@ -215,6 +215,26 @@ class Response extends Message {
throw new ArgumentError("Invalid status code: $statusCode.");
}
}
+
+ /// Creates a new [Response] by copying existing values and applying specified
+ /// changes.
+ ///
+ /// New key-value pairs in [context] and [headers] will be added to the copied
+ /// [Response].
+ ///
+ /// If [context] or [headers] includes a key that already exists, the
+ /// key-value pair will replace the corresponding entry in the copied
+ /// [Response].
+ ///
+ /// All other context and header values from the [Response] will be included
+ /// in the copied [Response] unchanged.
+ Response change({Map<String, String> headers, Map<String, Object> context}) {
+ headers = updateMap(this.headers, headers);
+ context = updateMap(this.context, context);
+
+ return new Response(this.statusCode, body: this.read(), headers: headers,
+ context: context);
+ }
}
/// Converts [body] to a byte stream.

Powered by Google App Engine
This is Rietveld 408576698