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

Unified Diff: pkg/shelf/lib/src/request.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/message.dart ('k') | pkg/shelf/lib/src/response.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/lib/src/request.dart
diff --git a/pkg/shelf/lib/src/request.dart b/pkg/shelf/lib/src/request.dart
index f7e011dc42609321c775d6d8ecc9bc7af582e78a..192a78227a9664ea5f1811ea27ab544d8738855b 100644
--- a/pkg/shelf/lib/src/request.dart
+++ b/pkg/shelf/lib/src/request.dart
@@ -9,6 +9,7 @@ import 'dart:async';
import 'package:http_parser/http_parser.dart';
import 'message.dart';
+import 'util.dart';
/// Represents an HTTP request to be processed by a Shelf application.
class Request extends Message {
@@ -81,8 +82,7 @@ class Request extends Message {
headers: headers, context: context) {
if (method.isEmpty) throw new ArgumentError('method cannot be empty.');
- // TODO(kevmoo) use isAbsolute property on Uri once Issue 18053 is fixed
- if (requestedUri.scheme.isEmpty) {
+ if (!requestedUri.isAbsolute) {
throw new ArgumentError('requstedUri must be an absolute URI.');
}
@@ -107,6 +107,27 @@ class Request extends Message {
throw new ArgumentError('scriptName and url cannot both be empty.');
}
}
+
+ /// Creates a new [Request] by copying existing values and applying specified
+ /// changes.
+ ///
+ /// New key-value pairs in [context] and [headers] will be added to the copied
+ /// [Request].
+ ///
+ /// If [context] or [headers] includes a key that already exists, the
+ /// key-value pair will replace the corresponding entry in the copied
+ /// [Request].
+ ///
+ /// All other context and header values from the [Request] will be included
+ /// in the copied [Request] unchanged.
+ Request change({Map<String, String> headers, Map<String, Object> context}) {
+ headers = updateMap(this.headers, headers);
+ context = updateMap(this.context, context);
+
+ return new Request(this.method, this.requestedUri,
+ protocolVersion: this.protocolVersion, headers: headers, url: this.url,
+ scriptName: this.scriptName, body: this.read(), context: context);
+ }
}
/// Computes `url` from the provided [Request] constructor arguments.
@@ -123,7 +144,6 @@ Uri _computeUrl(Uri requestedUri, Uri url, String scriptName) {
}
if (url != null && scriptName != null) {
- // TODO(kevmoo) use isAbsolute property on Uri once Issue 18053 is fixed
if (url.scheme.isNotEmpty) throw new ArgumentError('url must be relative.');
return url;
}
« no previous file with comments | « pkg/shelf/lib/src/message.dart ('k') | pkg/shelf/lib/src/response.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698