Make MediaType case-insensitive, following the spec.

R=kevmoo@google.com

Review URL: https://codereview.chromium.org//1419493002 .
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cdf85d4..08992e9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 1.1.0
+
+* The MIME spec says that media types and their parameter names are
+  case-insensitive. Accordingly, `MediaType` now uses a case-insensitive map for
+  its parameters and its `type` and `subtype` fields are now always lowercase.
+
 ## 1.0.0
 
 This is 1.0.0 because the API is stable—there are no breaking changes.
diff --git a/lib/src/media_type.dart b/lib/src/media_type.dart
index 5bae0ec..e15bccf 100644
--- a/lib/src/media_type.dart
+++ b/lib/src/media_type.dart
@@ -7,6 +7,7 @@
 import 'package:collection/collection.dart';
 import 'package:string_scanner/string_scanner.dart';
 
+import 'case_insensitive_map.dart';
 import 'scan.dart';
 import 'utils.dart';
 
@@ -21,14 +22,18 @@
 /// calling [change].
 class MediaType {
   /// The primary identifier of the MIME type.
+  ///
+  /// This is always lowercase. 
   final String type;
 
   /// The secondary identifier of the MIME type.
+  ///
+  /// This is always lowercase. 
   final String subtype;
 
   /// The parameters to the media type.
   ///
-  /// This map is immutable.
+  /// This map is immutable and the keys are case-insensitive.
   final Map<String, String> parameters;
 
   /// The media type's MIME type.
@@ -73,9 +78,11 @@
     });
   }
 
-  MediaType(this.type, this.subtype, [Map<String, String> parameters])
-      : this.parameters = new UnmodifiableMapView(
-          parameters == null ? {} : new Map.from(parameters));
+  MediaType(String type, String subtype, [Map<String, String> parameters])
+      : type = type.toLowerCase(),
+        subtype = subtype.toLowerCase(),
+        parameters = new UnmodifiableMapView(
+            parameters == null ? {} : new CaseInsensitiveMap.from(parameters));
 
   /// Returns a copy of this [MediaType] with some fields altered.
   ///
diff --git a/pubspec.yaml b/pubspec.yaml
index 06c3529..0c1d578 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: http_parser
-version: 1.0.0
+version: 1.1.0-dev
 author: "Dart Team <misc@dartlang.org>"
 homepage: https://github.com/dart-lang/http_parser
 description: >
diff --git a/test/media_type_test.dart b/test/media_type_test.dart
index 0a9f904..98f482b 100644
--- a/test/media_type_test.dart
+++ b/test/media_type_test.dart
@@ -70,6 +70,23 @@
       expect(
           type.parameters, equals({"foo": "bar space", "baz": "bang\\escape"}));
     });
+
+    test("lower-cases type and subtype", () {
+      var type = new MediaType.parse('TeXt/pLaIn');
+      expect(type.type, equals("text"));
+      expect(type.subtype, equals("plain"));
+      expect(type.mimeType, equals("text/plain"));
+    });
+
+    test("records parameters as case-insensitive", () {
+      var type = new MediaType.parse('test/plain;FoO=bar;bAz=bang');
+      expect(type.parameters, equals({
+        "FoO": "bar",
+        "bAz": "bang"
+      }));
+      expect(type.parameters, containsPair("foo", "bar"));
+      expect(type.parameters, containsPair("baz", "bang"));
+    });
   });
 
   group("change", () {