| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 7 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
| 8 | 8 |
| 9 class _WebSocketMessageType { | 9 class _WebSocketMessageType { |
| 10 static const int NONE = 0; | 10 static const int NONE = 0; |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 response.close(); | 374 response.close(); |
| 375 }); | 375 }); |
| 376 return; | 376 return; |
| 377 } | 377 } |
| 378 // Send the upgrade response. | 378 // Send the upgrade response. |
| 379 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; | 379 response.statusCode = HttpStatus.SWITCHING_PROTOCOLS; |
| 380 response.headers.add(HttpHeaders.CONNECTION, "Upgrade"); | 380 response.headers.add(HttpHeaders.CONNECTION, "Upgrade"); |
| 381 response.headers.add(HttpHeaders.UPGRADE, "websocket"); | 381 response.headers.add(HttpHeaders.UPGRADE, "websocket"); |
| 382 String key = request.headers.value("Sec-WebSocket-Key"); | 382 String key = request.headers.value("Sec-WebSocket-Key"); |
| 383 SHA1 sha1 = new SHA1(); | 383 SHA1 sha1 = new SHA1(); |
| 384 sha1.add("$key$_webSocketGUID".charCodes); | 384 sha1.add("$key$_webSocketGUID".codeUnits); |
| 385 String accept = _Base64._encode(sha1.close()); | 385 String accept = _Base64._encode(sha1.close()); |
| 386 response.headers.add("Sec-WebSocket-Accept", accept); | 386 response.headers.add("Sec-WebSocket-Accept", accept); |
| 387 response.headers.contentLength = 0; | 387 response.headers.contentLength = 0; |
| 388 response.detachSocket() | 388 response.detachSocket() |
| 389 .then((socket) { | 389 .then((socket) { |
| 390 _controller.add(new _WebSocketImpl._fromSocket(socket)); | 390 _controller.add(new _WebSocketImpl._fromSocket(socket)); |
| 391 }, onError: (error) { | 391 }, onError: (error) { |
| 392 _controller.signalError(error); | 392 _controller.signalError(error); |
| 393 }); | 393 }); |
| 394 }); | 394 }); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 (value) => value.toLowerCase() == "upgrade") || | 483 (value) => value.toLowerCase() == "upgrade") || |
| 484 response.headers.value(HttpHeaders.UPGRADE).toLowerCase() != | 484 response.headers.value(HttpHeaders.UPGRADE).toLowerCase() != |
| 485 "websocket") { | 485 "websocket") { |
| 486 error("Connection to '$uri' was not upgraded to websocket"); | 486 error("Connection to '$uri' was not upgraded to websocket"); |
| 487 } | 487 } |
| 488 String accept = response.headers.value("Sec-WebSocket-Accept"); | 488 String accept = response.headers.value("Sec-WebSocket-Accept"); |
| 489 if (accept == null) { | 489 if (accept == null) { |
| 490 error("Response did not contain a 'Sec-WebSocket-Accept' header"); | 490 error("Response did not contain a 'Sec-WebSocket-Accept' header"); |
| 491 } | 491 } |
| 492 SHA1 sha1 = new SHA1(); | 492 SHA1 sha1 = new SHA1(); |
| 493 sha1.add("$nonce$_webSocketGUID".charCodes); | 493 sha1.add("$nonce$_webSocketGUID".codeUnits); |
| 494 List<int> expectedAccept = sha1.close(); | 494 List<int> expectedAccept = sha1.close(); |
| 495 List<int> receivedAccept = _Base64._decode(accept); | 495 List<int> receivedAccept = _Base64._decode(accept); |
| 496 if (expectedAccept.length != receivedAccept.length) { | 496 if (expectedAccept.length != receivedAccept.length) { |
| 497 error("Reasponse header 'Sec-WebSocket-Accept' is the wrong length"); | 497 error("Reasponse header 'Sec-WebSocket-Accept' is the wrong length"); |
| 498 } | 498 } |
| 499 for (int i = 0; i < expectedAccept.length; i++) { | 499 for (int i = 0; i < expectedAccept.length; i++) { |
| 500 if (expectedAccept[i] != receivedAccept[i]) { | 500 if (expectedAccept[i] != receivedAccept[i]) { |
| 501 error("Bad response 'Sec-WebSocket-Accept' header"); | 501 error("Bad response 'Sec-WebSocket-Accept' header"); |
| 502 } | 502 } |
| 503 } | 503 } |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 676 |
| 677 class _WebSocketCloseEvent implements CloseEvent { | 677 class _WebSocketCloseEvent implements CloseEvent { |
| 678 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 678 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
| 679 bool get wasClean => _wasClean; | 679 bool get wasClean => _wasClean; |
| 680 int get code => _code; | 680 int get code => _code; |
| 681 String get reason => _reason; | 681 String get reason => _reason; |
| 682 bool _wasClean; | 682 bool _wasClean; |
| 683 int _code; | 683 int _code; |
| 684 String _reason; | 684 String _reason; |
| 685 } | 685 } |
| OLD | NEW |