Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(401)

Side by Side Diff: sdk/lib/io/websocket_impl.dart

Issue 897323002: Add support for user info on ws: and wss: URLs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Matches _WebSocketOpcode. 9 // Matches _WebSocketOpcode.
10 class _WebSocketMessageType { 10 class _WebSocketMessageType {
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 Timer _closeTimer; 768 Timer _closeTimer;
769 769
770 static final HttpClient _httpClient = new HttpClient(); 770 static final HttpClient _httpClient = new HttpClient();
771 771
772 static Future<WebSocket> connect( 772 static Future<WebSocket> connect(
773 String url, Iterable<String> protocols, Map<String, dynamic> headers) { 773 String url, Iterable<String> protocols, Map<String, dynamic> headers) {
774 Uri uri = Uri.parse(url); 774 Uri uri = Uri.parse(url);
775 if (uri.scheme != "ws" && uri.scheme != "wss") { 775 if (uri.scheme != "ws" && uri.scheme != "wss") {
776 throw new WebSocketException("Unsupported URL scheme '${uri.scheme}'"); 776 throw new WebSocketException("Unsupported URL scheme '${uri.scheme}'");
777 } 777 }
778 if (uri.userInfo != "") {
779 throw new WebSocketException("Unsupported user info '${uri.userInfo}'");
780 }
781 778
782 Random random = new Random(); 779 Random random = new Random();
783 // Generate 16 random bytes. 780 // Generate 16 random bytes.
784 Uint8List nonceData = new Uint8List(16); 781 Uint8List nonceData = new Uint8List(16);
785 for (int i = 0; i < 16; i++) { 782 for (int i = 0; i < 16; i++) {
786 nonceData[i] = random.nextInt(256); 783 nonceData[i] = random.nextInt(256);
787 } 784 }
788 String nonce = _CryptoUtils.bytesToBase64(nonceData); 785 String nonce = _CryptoUtils.bytesToBase64(nonceData);
789 786
790 uri = new Uri(scheme: uri.scheme == "wss" ? "https" : "http", 787 uri = new Uri(scheme: uri.scheme == "wss" ? "https" : "http",
791 userInfo: uri.userInfo, 788 userInfo: uri.userInfo,
792 host: uri.host, 789 host: uri.host,
793 port: uri.port, 790 port: uri.port,
794 path: uri.path, 791 path: uri.path,
795 query: uri.query, 792 query: uri.query,
796 fragment: uri.fragment); 793 fragment: uri.fragment);
797 return _httpClient.openUrl("GET", uri) 794 return _httpClient.openUrl("GET", uri)
798 .then((request) { 795 .then((request) {
796 if (uri.userInfo != null && !uri.userInfo.isEmpty) {
797 // If the URL contains user information use that for basic
798 // authorization.
799 String auth =
800 _CryptoUtils.bytesToBase64(UTF8.encode(uri.userInfo));
801 request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth");
802 }
799 if (headers != null) { 803 if (headers != null) {
800 headers.forEach((field, value) => request.headers.add(field, value)); 804 headers.forEach((field, value) => request.headers.add(field, value));
801 } 805 }
802 // Setup the initial handshake. 806 // Setup the initial handshake.
803 request.headers 807 request.headers
804 ..set(HttpHeaders.CONNECTION, "Upgrade") 808 ..set(HttpHeaders.CONNECTION, "Upgrade")
805 ..set(HttpHeaders.UPGRADE, "websocket") 809 ..set(HttpHeaders.UPGRADE, "websocket")
806 ..set("Sec-WebSocket-Key", nonce) 810 ..set("Sec-WebSocket-Key", nonce)
807 ..set("Cache-Control", "no-cache") 811 ..set("Cache-Control", "no-cache")
808 ..set("Sec-WebSocket-Version", "13"); 812 ..set("Sec-WebSocket-Version", "13");
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 (code < WebSocketStatus.NORMAL_CLOSURE || 1016 (code < WebSocketStatus.NORMAL_CLOSURE ||
1013 code == WebSocketStatus.RESERVED_1004 || 1017 code == WebSocketStatus.RESERVED_1004 ||
1014 code == WebSocketStatus.NO_STATUS_RECEIVED || 1018 code == WebSocketStatus.NO_STATUS_RECEIVED ||
1015 code == WebSocketStatus.ABNORMAL_CLOSURE || 1019 code == WebSocketStatus.ABNORMAL_CLOSURE ||
1016 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && 1020 (code > WebSocketStatus.INTERNAL_SERVER_ERROR &&
1017 code < WebSocketStatus.RESERVED_1015) || 1021 code < WebSocketStatus.RESERVED_1015) ||
1018 (code >= WebSocketStatus.RESERVED_1015 && 1022 (code >= WebSocketStatus.RESERVED_1015 &&
1019 code < 3000)); 1023 code < 3000));
1020 } 1024 }
1021 } 1025 }
OLDNEW
« no previous file with comments | « sdk/lib/io/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698