Merge branch 'Pacane/fix-header-content-type-case-comparison'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fbd6232..e81f3f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.6.4+2
+
+* Fix a bug where the `Content-Type` header didn't interact properly with the
+  `encoding` parameter for `new Request()` and `new Response()` if it wasn't
+  lowercase.
+
 ## 0.6.4+1
 
 * When the `shelf_io` adapter detects an error, print the request context as
diff --git a/lib/src/message.dart b/lib/src/message.dart
index 0d41b53..ac6e6ee 100644
--- a/lib/src/message.dart
+++ b/lib/src/message.dart
@@ -139,6 +139,8 @@
     Map<String, String> headers, Encoding encoding) {
   if (headers == null) headers = const {};
   if (encoding == null) return headers;
+
+  headers = new CaseInsensitiveMap.from(headers);
   if (headers['content-type'] == null) {
     return addHeader(headers, 'content-type',
         'application/octet-stream; charset=${encoding.name}');
diff --git a/pubspec.yaml b/pubspec.yaml
index 7c18f5e..8f60354 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: shelf
-version: 0.6.4+1
+version: 0.6.4+2
 author: Dart Team <misc@dartlang.org>
 description: Web Server Middleware for Dart
 homepage: https://github.com/dart-lang/shelf
diff --git a/test/message_test.dart b/test/message_test.dart
index 8a5abed..ddd6777 100644
--- a/test/message_test.dart
+++ b/test/message_test.dart
@@ -8,6 +8,7 @@
 import 'dart:convert';
 
 import 'package:shelf/src/message.dart';
+import 'package:shelf/src/response.dart';
 import 'package:test/test.dart';
 
 import 'test_util.dart';
@@ -204,6 +205,14 @@
       }).encoding, equals(LATIN1));
     });
 
+    test("comes from the content-type charset parameter with a different case",
+        () {
+      expect(_createMessage(
+          headers: {
+        'Content-Type': 'text/plain; charset=iso-8859-1'
+      }).encoding, equals(LATIN1));
+    });
+
     test("defaults to encoding a String as UTF-8", () {
       expect(_createMessage(body: "è").read().toList(),
           completion(equals([[195, 168]])));
@@ -221,6 +230,14 @@
           containsPair('content-type', 'text/plain; charset=iso-8859-1'));
     });
 
+    test("adds an explicit encoding to the content-type with a different case",
+        () {
+      var request = _createMessage(
+          body: "è", encoding: LATIN1, headers: {'Content-Type': 'text/plain'});
+      expect(request.headers,
+          containsPair('Content-Type', 'text/plain; charset=iso-8859-1'));
+    });
+
     test("sets an absent content-type to application/octet-stream in order to "
         "set the charset", () {
       var request = _createMessage(body: "è", encoding: LATIN1);