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

Unified Diff: sdk/lib/io/websocket_impl.dart

Issue 839063005: Allow additional headers for WebSocket connect (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/websocket.dart ('k') | tests/standalone/io/web_socket_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/websocket_impl.dart
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart
index 872cd321ad7b223deadefd840311925fe9f123b8..ae4c91ce6208f76e2d346c701f2e5fe0831a2786 100644
--- a/sdk/lib/io/websocket_impl.dart
+++ b/sdk/lib/io/websocket_impl.dart
@@ -401,7 +401,7 @@ class _WebSocketTransformerImpl implements WebSocketTransformer {
sha1.add("$key$_webSocketGUID".codeUnits);
String accept = _CryptoUtils.bytesToBase64(sha1.close());
response.headers.add("Sec-WebSocket-Accept", accept);
- if (protocol != null && protocol.isNotEmpty) {
+ if (protocol != null) {
response.headers.add("Sec-WebSocket-Protocol", protocol);
}
response.headers.contentLength = 0;
@@ -769,7 +769,8 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
static final HttpClient _httpClient = new HttpClient();
- static Future<WebSocket> connect(String url, List<String> protocols) {
+ static Future<WebSocket> connect(
+ String url, Iterable<String> protocols, Map<String, dynamic> headers) {
Uri uri = Uri.parse(url);
if (uri.scheme != "ws" && uri.scheme != "wss") {
throw new WebSocketException("Unsupported URL scheme '${uri.scheme}'");
@@ -795,15 +796,18 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
fragment: uri.fragment);
return _httpClient.openUrl("GET", uri)
.then((request) {
+ if (headers != null) {
+ headers.forEach((field, value) => request.headers.add(field, value));
+ }
// Setup the initial handshake.
request.headers
- ..add(HttpHeaders.CONNECTION, "Upgrade")
+ ..set(HttpHeaders.CONNECTION, "Upgrade")
..set(HttpHeaders.UPGRADE, "websocket")
..set("Sec-WebSocket-Key", nonce)
..set("Cache-Control", "no-cache")
..set("Sec-WebSocket-Version", "13");
- if (protocols.isNotEmpty) {
- request.headers.add("Sec-WebSocket-Protocol", protocols);
+ if (protocols != null) {
+ request.headers.add("Sec-WebSocket-Protocol", protocols.toList());
}
return request.close();
})
« 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