OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library shelf_web_socket.web_socket_test; | 5 library shelf_web_socket.web_socket_test; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
10 import 'package:shelf/shelf_io.dart' as shelf_io; | 10 import 'package:shelf/shelf_io.dart' as shelf_io; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 expect(http.get(url, headers: headers), hasStatus(101)); | 98 expect(http.get(url, headers: headers), hasStatus(101)); |
99 }); | 99 }); |
100 | 100 |
101 test("ignores the case of the server origin", () { | 101 test("ignores the case of the server origin", () { |
102 var headers = _handshakeHeaders; | 102 var headers = _handshakeHeaders; |
103 headers['Origin'] = 'google.com'; | 103 headers['Origin'] = 'google.com'; |
104 expect(http.get(url, headers: headers), hasStatus(101)); | 104 expect(http.get(url, headers: headers), hasStatus(101)); |
105 }); | 105 }); |
106 }); | 106 }); |
107 | 107 |
| 108 // Regression test for issue 21894. |
| 109 test("allows a Connection header with multiple values", () { |
| 110 return shelf_io.serve(webSocketHandler((webSocket) { |
| 111 webSocket.close(); |
| 112 }), "localhost", 0).then((server) { |
| 113 var url = 'http://localhost:${server.port}/'; |
| 114 |
| 115 var headers = _handshakeHeaders; |
| 116 headers['Connection'] = 'Other-Token, Upgrade'; |
| 117 expect(http.get(url, headers: headers).whenComplete(server.close), |
| 118 hasStatus(101)); |
| 119 }); |
| 120 }); |
| 121 |
108 group("HTTP errors", () { | 122 group("HTTP errors", () { |
109 var server; | 123 var server; |
110 var url; | 124 var url; |
111 setUp(() { | 125 setUp(() { |
112 return shelf_io.serve(webSocketHandler((_) { | 126 return shelf_io.serve(webSocketHandler((_) { |
113 fail("should not create a WebSocket"); | 127 fail("should not create a WebSocket"); |
114 }), "localhost", 0).then((server_) { | 128 }), "localhost", 0).then((server_) { |
115 server = server_; | 129 server = server_; |
116 url = 'http://localhost:${server.port}/'; | 130 url = 'http://localhost:${server.port}/'; |
117 }); | 131 }); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 expect(() => webSocketHandler((_) => null, protocols: ['foo']), | 172 expect(() => webSocketHandler((_) => null, protocols: ['foo']), |
159 throwsArgumentError); | 173 throwsArgumentError); |
160 }); | 174 }); |
161 } | 175 } |
162 | 176 |
163 Matcher hasStatus(int status) => completion(predicate((response) { | 177 Matcher hasStatus(int status) => completion(predicate((response) { |
164 expect(response, new isInstanceOf<http.Response>()); | 178 expect(response, new isInstanceOf<http.Response>()); |
165 expect(response.statusCode, equals(status)); | 179 expect(response.statusCode, equals(status)); |
166 return true; | 180 return true; |
167 })); | 181 })); |
OLD | NEW |