| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert' as convert; |
| 6 | 7 |
| 7 import 'package:async/async.dart'; | 8 import 'package:async/async.dart'; |
| 8 import 'package:crypto/crypto.dart'; | 9 import 'package:crypto/crypto.dart'; |
| 9 import 'package:stream_channel/stream_channel.dart'; | 10 import 'package:stream_channel/stream_channel.dart'; |
| 10 | 11 |
| 11 import 'copy/web_socket_impl.dart'; | 12 import 'copy/web_socket_impl.dart'; |
| 12 | 13 |
| 13 /// A [StreamChannel] that communicates over a WebSocket. | 14 /// A [StreamChannel] that communicates over a WebSocket. |
| 14 /// | 15 /// |
| 15 /// This is implemented by classes that use `dart:io` and `dart:html`. The [new | 16 /// This is implemented by classes that use `dart:io` and `dart:html`. The [new |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 /// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of | 58 /// Signs a `Sec-WebSocket-Key` header sent by a WebSocket client as part of |
| 58 /// the [initial handshake][]. | 59 /// the [initial handshake][]. |
| 59 /// | 60 /// |
| 60 /// The return value should be sent back to the client in a | 61 /// The return value should be sent back to the client in a |
| 61 /// `Sec-WebSocket-Accept` header. | 62 /// `Sec-WebSocket-Accept` header. |
| 62 /// | 63 /// |
| 63 /// [initial handshake]: https://tools.ietf.org/html/rfc6455#section-4.2.2 | 64 /// [initial handshake]: https://tools.ietf.org/html/rfc6455#section-4.2.2 |
| 64 static String signKey(String key) { | 65 static String signKey(String key) { |
| 65 // We use [codeUnits] here rather than UTF-8-decoding the string because | 66 // We use [codeUnits] here rather than UTF-8-decoding the string because |
| 66 // [key] is expected to be base64 encoded, and so will be pure ASCII. | 67 // [key] is expected to be base64 encoded, and so will be pure ASCII. |
| 67 return BASE64.encode(sha1.convert((key + webSocketGUID).codeUnits).bytes); | 68 return convert.BASE64.encode( |
| 69 sha1.convert((key + webSocketGUID).codeUnits).bytes); |
| 68 } | 70 } |
| 69 | 71 |
| 70 /// Creates a new WebSocket handling messaging across an existing [channel]. | 72 /// Creates a new WebSocket handling messaging across an existing [channel]. |
| 71 /// | 73 /// |
| 72 /// This is a cross-platform constructor; it doesn't use either `dart:io` or | 74 /// This is a cross-platform constructor; it doesn't use either `dart:io` or |
| 73 /// `dart:html`. It's also HTTP-API-agnostic, which means that the initial | 75 /// `dart:html`. It's also HTTP-API-agnostic, which means that the initial |
| 74 /// [WebSocket handshake][] must have already been completed on the socket | 76 /// [WebSocket handshake][] must have already been completed on the socket |
| 75 /// before this is called. | 77 /// before this is called. |
| 76 /// | 78 /// |
| 77 /// [protocol] should be the protocol negotiated by this handshake, if any. | 79 /// [protocol] should be the protocol negotiated by this handshake, if any. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 /// | 111 /// |
| 110 /// [closeCode] and [closeReason] are the [close code][] and [reason][] sent | 112 /// [closeCode] and [closeReason] are the [close code][] and [reason][] sent |
| 111 /// to the remote peer, respectively. If they are omitted, the peer will see | 113 /// to the remote peer, respectively. If they are omitted, the peer will see |
| 112 /// a "no status received" code with no reason. | 114 /// a "no status received" code with no reason. |
| 113 /// | 115 /// |
| 114 /// [close code]: https://tools.ietf.org/html/rfc6455#section-7.1.5 | 116 /// [close code]: https://tools.ietf.org/html/rfc6455#section-7.1.5 |
| 115 /// [reason]: https://tools.ietf.org/html/rfc6455#section-7.1.6 | 117 /// [reason]: https://tools.ietf.org/html/rfc6455#section-7.1.6 |
| 116 Future close([int closeCode, String closeReason]) => | 118 Future close([int closeCode, String closeReason]) => |
| 117 _webSocket.close(closeCode, closeReason); | 119 _webSocket.close(closeCode, closeReason); |
| 118 } | 120 } |
| OLD | NEW |