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

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: nevermind Created 6 years, 7 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
« no previous file with comments | « pkg/shelf/lib/src/request.dart ('k') | pkg/shelf/lib/src/shelf_unmodifiable_map.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c36c551a5a177ddcf6fae74d675e69af640b0e49 100644
--- a/pkg/shelf/lib/src/response.dart
+++ b/pkg/shelf/lib/src/response.dart
@@ -10,6 +10,7 @@ import 'dart:convert';
import 'package:http_parser/http_parser.dart';
import 'message.dart';
+import 'util.dart';
/// The response returned by a [Handler].
class Response extends Message {
@@ -53,7 +54,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 +119,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 +134,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 +170,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 +216,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.
« no previous file with comments | « pkg/shelf/lib/src/request.dart ('k') | pkg/shelf/lib/src/shelf_unmodifiable_map.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698