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

Unified Diff: pkg/shelf/lib/src/message.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 | « no previous file | 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 1b2e966c4660b3375519c985a459362257e00408..1522e1301aac2ca2af36caec47af853ddbec111f 100644
--- a/pkg/shelf/lib/src/message.dart
+++ b/pkg/shelf/lib/src/message.dart
@@ -5,14 +5,13 @@
library shelf.message;
import 'dart:async';
-import 'dart:collection';
import 'dart:convert';
-// 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';
+import 'shelf_unmodifiable_map.dart';
+
/// Represents logic shared between [Request] and [Response].
abstract class Message {
/// The HTTP headers.
@@ -43,9 +42,10 @@ abstract class Message {
/// If [headers] is `null`, it is treated as empty.
Message(this._body, {Map<String, String> headers,
Map<String, Object> context})
- : this.headers = _getIgnoreCaseMapView(headers),
- this.context = new pc.UnmodifiableMapView(
- context == null ? const {} : new Map.from(context));
+ : this.headers = new ShelfUnmodifiableMap<String>(headers,
+ ignoreKeyCase: true),
+ this.context = new ShelfUnmodifiableMap<Object>(context,
+ ignoreKeyCase: false);
/// The contents of the content-length field in [headers].
///
@@ -112,18 +112,8 @@ abstract class Message {
if (encoding == null) encoding = UTF8;
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);
+ /// Creates a new [Message] by copying existing values and applying specified
+ /// changes.
+ Message change({Map<String, String> headers, Map<String, Object> context});
}
« no previous file with comments | « no previous file | pkg/shelf/lib/src/request.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698