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

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: updating note in Request about absolute Uri 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
« no previous file with comments | « no previous file | pkg/shelf/test/request_test.dart » ('j') | pkg/shelf/test/request_test.dart » ('J')
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..4a719601efbe07a2f91d9f18e7d55bee221f09f8 100644
--- a/pkg/shelf/lib/src/request.dart
+++ b/pkg/shelf/lib/src/request.dart
@@ -81,7 +81,9 @@ 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
+ // NOTE: A Uri with a #fragment is is not considered 'absolute' per
+ // http://tools.ietf.org/html/rfc3986#section-4.3
+ // So instead of using Uri.isAbsolute, just checking for an empty scheme
nweiz 2014/04/28 22:13:33 Use full sentences in comments.
kevmoo 2014/04/29 10:41:54 Done.
if (requestedUri.scheme.isEmpty) {
kevmoo 2014/04/26 16:34:34 The RFC is a bit weird about fragments, hence Uri.
nweiz 2014/04/28 22:13:33 I think we should use [isAbsolute] here. The reque
kevmoo 2014/04/29 10:41:54 I double checked. dart_io doesn't send the fragmen
throw new ArgumentError('requstedUri must be an absolute URI.');
}
@@ -107,6 +109,33 @@ class Request extends Message {
throw new ArgumentError('scriptName and url cannot both be empty.');
}
}
+
+ /// Copies the request updated [context] and [headers] values.
nweiz 2014/04/28 22:13:33 Fix this sentence.
kevmoo 2014/04/29 10:41:54 Done.
+ ///
+ /// 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 copy({Map<String, String> headers, Map<String, Object> context}) {
nweiz 2014/04/28 22:13:33 We should discuss this name a bit. I like "copy" o
kevmoo 2014/04/29 10:41:54 Done.
+ headers = _updatedMap(this.headers, headers);
+ context = _updatedMap(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);
nweiz 2014/04/28 22:13:33 I don't like that this copies the headers and re-w
kevmoo 2014/04/29 10:41:54 Done.
+ }
+}
+
+Map _updatedMap(Map original, Map updates) {
nweiz 2014/04/28 22:13:33 Functions should have verb names, e.g. "_updateMap
kevmoo 2014/04/29 10:41:54 Done.
+ if (updates == null || updates.isEmpty) return original;
+
+ return new Map.from(original)
+ ..addAll(updates);
}
/// Computes `url` from the provided [Request] constructor arguments.
« no previous file with comments | « no previous file | pkg/shelf/test/request_test.dart » ('j') | pkg/shelf/test/request_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698