Fix shelf_web_socket's Connection handling.

R=rnystrom@google.com
BUG=21894

Review URL: https://codereview.chromium.org//810133002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/shelf_web_socket@42446 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..d12b690
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,4 @@
+## 0.0.1+1
+
+* Properly parse the `Connection` header. This fixes an issue where Firefox was
+  unable to connect.
diff --git a/lib/src/web_socket_handler.dart b/lib/src/web_socket_handler.dart
index ac5786a..7ab8e7e 100644
--- a/lib/src/web_socket_handler.dart
+++ b/lib/src/web_socket_handler.dart
@@ -28,7 +28,9 @@
 
     var connection = request.headers['Connection'];
     if (connection == null) return _notFound();
-    if (connection.toLowerCase() != 'upgrade') return _notFound();
+    var tokens = connection.toLowerCase().split(',')
+        .map((token) => token.trim());
+    if (!tokens.contains('upgrade')) return _notFound();
 
     var upgrade = request.headers['Upgrade'];
     if (upgrade == null) return _notFound();
diff --git a/pubspec.yaml b/pubspec.yaml
index 7cecc42..a19a331 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: shelf_web_socket
-version: 0.0.1
+version: 0.0.1+1
 author: "Dart Team <misc@dartlang.org>"
 homepage: http://www.dartlang.org
 description: >
diff --git a/test/web_socket_test.dart b/test/web_socket_test.dart
index f9ae2dc..aa9ea41 100644
--- a/test/web_socket_test.dart
+++ b/test/web_socket_test.dart
@@ -105,6 +105,20 @@
     });
   });
 
+  // Regression test for issue 21894.
+  test("allows a Connection header with multiple values", () {
+    return shelf_io.serve(webSocketHandler((webSocket) {
+      webSocket.close();
+    }), "localhost", 0).then((server) {
+      var url = 'http://localhost:${server.port}/';
+
+      var headers = _handshakeHeaders;
+      headers['Connection'] = 'Other-Token, Upgrade';
+      expect(http.get(url, headers: headers).whenComplete(server.close),
+          hasStatus(101));
+    });
+  });
+
   group("HTTP errors", () {
     var server;
     var url;