Use CaseInsensitiveMap from pkg/http_handler
...and UnmodifiableMapView from dart:collection
R=nweiz@google.com
Review URL: https://codereview.chromium.org//1413933003 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a01f6e9..46f2735 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.6.3+1
+
+* Cleaned up handling of certain `Map` instances and related dependencies.
+
## 0.6.3
* Messages returned by `Request.change()` and `Response.change()` are marked
diff --git a/lib/src/shelf_unmodifiable_map.dart b/lib/src/shelf_unmodifiable_map.dart
index d07ebfd..46b4223 100644
--- a/lib/src/shelf_unmodifiable_map.dart
+++ b/lib/src/shelf_unmodifiable_map.dart
@@ -6,11 +6,13 @@
import 'dart:collection';
-import 'package:collection/wrappers.dart' as pc;
+import 'package:http_parser/http_parser.dart';
-/// A simple wrapper over [pc.UnmodifiableMapView] which avoids re-wrapping
-/// itself.
+/// A simple wrapper over [UnmodifiableMapView] which avoids re-wrapping itself.
class ShelfUnmodifiableMap<V> extends UnmodifiableMapView<String, V> {
+ /// `true` if the key values are already lowercase.
+ final bool _ignoreKeyCase;
+
/// If [source] is a [ShelfUnmodifiableMap] with matching [ignoreKeyCase],
/// then [source] is returned.
///
@@ -22,7 +24,10 @@
/// after constructions are not reflected.
factory ShelfUnmodifiableMap(Map<String, V> source,
{bool ignoreKeyCase: false}) {
- if (source is ShelfUnmodifiableMap<V>) {
+ if (source is ShelfUnmodifiableMap<V> &&
+ // !ignoreKeyCase: no transformation of the input is required
+ // source._ignoreKeyCase: the input cannot be transformed any more
+ (!ignoreKeyCase || source._ignoreKeyCase)) {
return source;
}
@@ -31,22 +36,21 @@
}
if (ignoreKeyCase) {
- source = new pc.CanonicalizedMap<String, String, V>.from(
- source, (key) => key.toLowerCase(), isValidKey: (key) => key != null);
+ source = new CaseInsensitiveMap<V>.from(source);
} else {
source = new Map<String, V>.from(source);
}
- return new ShelfUnmodifiableMap<V>._(source);
+ return new ShelfUnmodifiableMap<V>._(source, ignoreKeyCase);
}
- ShelfUnmodifiableMap._(Map<String, V> source) : super(source);
+ ShelfUnmodifiableMap._(Map<String, V> source, this._ignoreKeyCase)
+ : super(source);
}
-/// An const empty implementation of [ShelfUnmodifiableMap].
-// TODO(kevmoo): Consider using MapView from dart:collection which has a const
-// ctor. Would require updating min SDK to 1.5.
-class _EmptyShelfUnmodifiableMap<V> extends pc.DelegatingMap<String, V>
+/// A const implementation of an empty [ShelfUnmodifiableMap].
+class _EmptyShelfUnmodifiableMap<V> extends MapView<String, V>
implements ShelfUnmodifiableMap<V> {
+ bool get _ignoreKeyCase => true;
const _EmptyShelfUnmodifiableMap() : super(const {});
}
diff --git a/pubspec.yaml b/pubspec.yaml
index 28fc35a..dfdfeaf 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,13 +1,12 @@
name: shelf
-version: 0.6.3
+version: 0.6.3+1
author: Dart Team <misc@dartlang.org>
description: Web Server Middleware for Dart
homepage: https://github.com/dart-lang/shelf
environment:
sdk: '>=1.9.0 <2.0.0'
dependencies:
- collection: '^1.0.0'
- http_parser: '>=0.0.0 <2.0.0'
+ http_parser: '^1.0.0'
path: '^1.0.0'
stack_trace: '^1.0.0'
dev_dependencies: