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

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

Issue 2529393002: Make core libraries use generic method syntax. (Closed)
Patch Set: Merge to head Created 4 years 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
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 const String _clientNoContextTakeover = "client_no_context_takeover"; 8 const String _clientNoContextTakeover = "client_no_context_takeover";
9 const String _serverNoContextTakeover = "server_no_context_takeover"; 9 const String _serverNoContextTakeover = "server_no_context_takeover";
10 const String _clientMaxWindowBits = "client_max_window_bits"; 10 const String _clientMaxWindowBits = "client_max_window_bits";
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 sha1.add("$key$_webSocketGUID".codeUnits); 446 sha1.add("$key$_webSocketGUID".codeUnits);
447 String accept = _CryptoUtils.bytesToBase64(sha1.close()); 447 String accept = _CryptoUtils.bytesToBase64(sha1.close());
448 response.headers.add("Sec-WebSocket-Accept", accept); 448 response.headers.add("Sec-WebSocket-Accept", accept);
449 if (protocol != null) { 449 if (protocol != null) {
450 response.headers.add("Sec-WebSocket-Protocol", protocol); 450 response.headers.add("Sec-WebSocket-Protocol", protocol);
451 } 451 }
452 452
453 var deflate = _negotiateCompression(request, response, compression); 453 var deflate = _negotiateCompression(request, response, compression);
454 454
455 response.headers.contentLength = 0; 455 response.headers.contentLength = 0;
456 return response.detachSocket().then/*<WebSocket>*/((socket) => 456 return response.detachSocket().then<WebSocket>((socket) =>
457 new _WebSocketImpl._fromSocket( 457 new _WebSocketImpl._fromSocket(
458 socket, protocol, compression, true, deflate)); 458 socket, protocol, compression, true, deflate));
459 } 459 }
460 460
461 var protocols = request.headers['Sec-WebSocket-Protocol']; 461 var protocols = request.headers['Sec-WebSocket-Protocol'];
462 if (protocols != null && _protocolSelector != null) { 462 if (protocols != null && _protocolSelector != null) {
463 // The suggested protocols can be spread over multiple lines, each 463 // The suggested protocols can be spread over multiple lines, each
464 // consisting of multiple protocols. To unify all of them, first join 464 // consisting of multiple protocols. To unify all of them, first join
465 // the lists with ', ' and then tokenize. 465 // the lists with ', ' and then tokenize.
466 protocols = _HttpParser._tokenizeFieldValue(protocols.join(', ')); 466 protocols = _HttpParser._tokenizeFieldValue(protocols.join(', '));
467 return new Future<String>(() => _protocolSelector(protocols)) 467 return new Future<String>(() => _protocolSelector(protocols))
468 .then/*<String>*/((protocol) { 468 .then<String>((protocol) {
469 if (protocols.indexOf(protocol) < 0) { 469 if (protocols.indexOf(protocol) < 0) {
470 throw new WebSocketException( 470 throw new WebSocketException(
471 "Selected protocol is not in the list of available protocols"); 471 "Selected protocol is not in the list of available protocols");
472 } 472 }
473 return protocol; 473 return protocol;
474 }).catchError((error) { 474 }).catchError((error) {
475 response 475 response
476 ..statusCode = HttpStatus.INTERNAL_SERVER_ERROR 476 ..statusCode = HttpStatus.INTERNAL_SERVER_ERROR
477 ..close(); 477 ..close();
478 throw error; 478 throw error;
479 }).then/*<WebSocket>*/(upgrade); 479 }).then<WebSocket>(upgrade);
480 } else { 480 } else {
481 return upgrade(null); 481 return upgrade(null);
482 } 482 }
483 } 483 }
484 484
485 static _WebSocketPerMessageDeflate _negotiateCompression(HttpRequest request, 485 static _WebSocketPerMessageDeflate _negotiateCompression(HttpRequest request,
486 HttpResponse response, CompressionOptions compression) { 486 HttpResponse response, CompressionOptions compression) {
487 var extensionHeader = request.headers.value("Sec-WebSocket-Extensions"); 487 var extensionHeader = request.headers.value("Sec-WebSocket-Extensions");
488 488
489 extensionHeader ??= ""; 489 extensionHeader ??= "";
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 for (int i = 0; i < expectedAccept.length; i++) { 1044 for (int i = 0; i < expectedAccept.length; i++) {
1045 if (expectedAccept[i] != receivedAccept[i]) { 1045 if (expectedAccept[i] != receivedAccept[i]) {
1046 error("Bad response 'Sec-WebSocket-Accept' header"); 1046 error("Bad response 'Sec-WebSocket-Accept' header");
1047 } 1047 }
1048 } 1048 }
1049 var protocol = response.headers.value('Sec-WebSocket-Protocol'); 1049 var protocol = response.headers.value('Sec-WebSocket-Protocol');
1050 1050
1051 _WebSocketPerMessageDeflate deflate = 1051 _WebSocketPerMessageDeflate deflate =
1052 negotiateClientCompression(response, compression); 1052 negotiateClientCompression(response, compression);
1053 1053
1054 return response.detachSocket().then/*<WebSocket>*/((socket) => 1054 return response.detachSocket().then<WebSocket>((socket) =>
1055 new _WebSocketImpl._fromSocket( 1055 new _WebSocketImpl._fromSocket(
1056 socket, protocol, compression, false, deflate)); 1056 socket, protocol, compression, false, deflate));
1057 }); 1057 });
1058 } 1058 }
1059 1059
1060 static _WebSocketPerMessageDeflate negotiateClientCompression( 1060 static _WebSocketPerMessageDeflate negotiateClientCompression(
1061 HttpClientResponse response, CompressionOptions compression) { 1061 HttpClientResponse response, CompressionOptions compression) {
1062 String extensionHeader = response.headers.value('Sec-WebSocket-Extensions'); 1062 String extensionHeader = response.headers.value('Sec-WebSocket-Extensions');
1063 1063
1064 if (extensionHeader == null) { 1064 if (extensionHeader == null) {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 return code != null && 1268 return code != null &&
1269 (code < WebSocketStatus.NORMAL_CLOSURE || 1269 (code < WebSocketStatus.NORMAL_CLOSURE ||
1270 code == WebSocketStatus.RESERVED_1004 || 1270 code == WebSocketStatus.RESERVED_1004 ||
1271 code == WebSocketStatus.NO_STATUS_RECEIVED || 1271 code == WebSocketStatus.NO_STATUS_RECEIVED ||
1272 code == WebSocketStatus.ABNORMAL_CLOSURE || 1272 code == WebSocketStatus.ABNORMAL_CLOSURE ||
1273 (code > WebSocketStatus.INTERNAL_SERVER_ERROR && 1273 (code > WebSocketStatus.INTERNAL_SERVER_ERROR &&
1274 code < WebSocketStatus.RESERVED_1015) || 1274 code < WebSocketStatus.RESERVED_1015) ||
1275 (code >= WebSocketStatus.RESERVED_1015 && code < 3000)); 1275 (code >= WebSocketStatus.RESERVED_1015 && code < 3000));
1276 } 1276 }
1277 } 1277 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698