| 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 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 5 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
| 6 | 6 |
| 7 class _WebSocketMessageType { | 7 class _WebSocketMessageType { |
| 8 static const int NONE = 0; | 8 static const int NONE = 0; |
| 9 static const int BINARY = 1; | 9 static const int BINARY = 1; |
| 10 static const int TEXT = 2; | 10 static const int TEXT = 2; |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 class _WebSocket implements WebSocket { | 768 class _WebSocket implements WebSocket { |
| 769 _WebSocket(String url, [protocols]) { | 769 _WebSocket(String url, [protocols]) { |
| 770 Uri uri = new Uri.fromString(url); | 770 Uri uri = new Uri.fromString(url); |
| 771 if (uri.scheme != "ws") { | 771 if (uri.scheme != "ws") { |
| 772 throw new WebSocketException("Unsupported URL scheme ${uri.scheme}"); | 772 throw new WebSocketException("Unsupported URL scheme ${uri.scheme}"); |
| 773 } | 773 } |
| 774 if (uri.userInfo != "") { | 774 if (uri.userInfo != "") { |
| 775 throw new WebSocketException("Unsupported user info ${uri.userInfo}"); | 775 throw new WebSocketException("Unsupported user info ${uri.userInfo}"); |
| 776 } | 776 } |
| 777 int port = uri.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : uri.port; | 777 int port = uri.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : uri.port; |
| 778 String path; | 778 String path = uri.path; |
| 779 if (path.length == 0) path = "/"; |
| 779 if (uri.query != "") { | 780 if (uri.query != "") { |
| 780 if (uri.fragment != "") { | 781 if (uri.fragment != "") { |
| 781 path = "${uri.path}?${uri.query}#${uri.fragment}"; | 782 path = "${path}?${uri.query}#${uri.fragment}"; |
| 782 } else { | 783 } else { |
| 783 path = "${uri.path}?${uri.query}"; | 784 path = "${path}?${uri.query}"; |
| 784 } | 785 } |
| 785 } else { | |
| 786 path = uri.path; | |
| 787 } | 786 } |
| 788 | 787 |
| 789 HttpClient client = new HttpClient(); | 788 HttpClient client = new HttpClient(); |
| 790 HttpClientConnection conn = client.open("GET", uri.domain, port, path); | 789 HttpClientConnection conn = client.open("GET", uri.domain, port, path); |
| 791 if (protocols is String) protocols = [protocols]; | 790 if (protocols is String) protocols = [protocols]; |
| 792 _wsconn = new WebSocketClientConnection(conn, protocols); | 791 _wsconn = new WebSocketClientConnection(conn, protocols); |
| 793 _wsconn.onOpen = () { | 792 _wsconn.onOpen = () { |
| 794 // HTTP client not needed after socket have been detached. | 793 // HTTP client not needed after socket have been detached. |
| 795 client.shutdown(); | 794 client.shutdown(); |
| 796 client = null; | 795 client = null; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 | 863 |
| 865 class _WebSocketCloseEvent implements CloseEvent { | 864 class _WebSocketCloseEvent implements CloseEvent { |
| 866 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 865 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
| 867 bool get wasClean => _wasClean; | 866 bool get wasClean => _wasClean; |
| 868 int get code => _code; | 867 int get code => _code; |
| 869 String get reason => _reason; | 868 String get reason => _reason; |
| 870 bool _wasClean; | 869 bool _wasClean; |
| 871 int _code; | 870 int _code; |
| 872 String _reason; | 871 String _reason; |
| 873 } | 872 } |
| OLD | NEW |