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

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

Issue 227563010: pkg/shelf: case-insensitive headers, cleaner Request ctor, a lot more tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixing dependent code, changelog 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 | « pkg/shelf/lib/src/handlers/logger.dart ('k') | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/shelf/lib/src/message.dart
diff --git a/pkg/shelf/lib/src/message.dart b/pkg/shelf/lib/src/message.dart
index 737c72224f88ee21172239a971e776371ddf7dba..ad64d10ea31604ae930400e60e4cb3955ffcbc5d 100644
--- a/pkg/shelf/lib/src/message.dart
+++ b/pkg/shelf/lib/src/message.dart
@@ -5,9 +5,11 @@
library shelf.message;
import 'dart:async';
+import 'dart:collection';
import 'dart:convert';
-import 'package:collection/wrappers.dart';
+// TODO(kevmoo): use UnmodifiableMapView from SDK once 1.4 ships
+import 'package:collection/wrappers.dart' as pc;
import 'package:http_parser/http_parser.dart';
import 'package:stack_trace/stack_trace.dart';
@@ -23,8 +25,11 @@ abstract class Message {
/// This can be read via [read] or [readAsString].
final Stream<List<int>> _body;
- Message(UnmodifiableMapView<String, String> headers, this._body)
- : this.headers = headers;
+ /// Creates a new [Message].
+ ///
+ /// If [headers] is `null`, it is treated as empty.
+ Message(this._body, {Map<String, String> headers})
+ : this.headers = _getIgnoreCaseMapView(headers);
/// The contents of the content-length field in [headers].
///
@@ -92,3 +97,17 @@ abstract class Message {
return Chain.track(encoding.decodeStream(read()));
}
}
+
+/// Creates on an unmodifiable map of [headers] with case-insensitive access.
+Map<String, String> _getIgnoreCaseMapView(Map<String, String> headers) {
+ if (headers == null) return const {};
+ // TODO(kevmoo) generalize this model with a 'canonical map' to align with
+ // similiar implementation in http pkg [BaseRequest].
+ var map = new LinkedHashMap<String, String>(
+ equals: (key1, key2) => key1.toLowerCase() == key2.toLowerCase(),
+ hashCode: (key) => key.toLowerCase().hashCode);
+
+ map.addAll(headers);
+
+ return new pc.UnmodifiableMapView<String, String>(map);
+}
« no previous file with comments | « pkg/shelf/lib/src/handlers/logger.dart ('k') | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698