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

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

Issue 91223002: Add support for Websocket protocols. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix selecting invalid protocol and document. Created 7 years, 1 month 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/http_parser.dart ('k') | sdk/lib/io/websocket_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/websocket.dart
diff --git a/sdk/lib/io/websocket.dart b/sdk/lib/io/websocket.dart
index a3f2b258e4d97fbf4e845491832d583ef7d9118f..1e2d0fa2cc75111896dc0a4cbe6f5ddda5c468db 100644
--- a/sdk/lib/io/websocket.dart
+++ b/sdk/lib/io/websocket.dart
@@ -53,7 +53,18 @@ abstract class WebSocketStatus {
*/
abstract class WebSocketTransformer
implements StreamTransformer<HttpRequest, WebSocket> {
- factory WebSocketTransformer() => new _WebSocketTransformerImpl();
+
+ /**
+ * Create a new [WebSocketTransformer].
+ *
+ * If [protocolSelector] is provided, [protocolSelector] will be called to
+ * select what protocol to use, if any were provided by the client.
+ * [protocolSelector] is should return either a [String] or a [Future]
+ * completing with a [String]. The [String] must exist in the list of
+ * protocols.
+ */
+ factory WebSocketTransformer({protocolSelector(List<String> protocols)})
+ => new _WebSocketTransformerImpl(protocolSelector);
/**
* Upgrades a [HttpRequest] to a [WebSocket] connection. If the
@@ -61,9 +72,16 @@ abstract class WebSocketTransformer
* with status code 500 will be returned. Otherwise the returned
* future will complete with the [WebSocket] when the upgrade pocess
* is complete.
+ *
+ * If [protocolSelector] is provided, [protocolSelector] will be called to
+ * select what protocol to use, if any were provided by the client.
+ * [protocolSelector] is should return either a [String] or a [Future]
+ * completing with a [String]. The [String] must exist in the list of
+ * protocols.
*/
- static Future<WebSocket> upgrade(HttpRequest request) {
- return _WebSocketTransformerImpl._upgrade(request);
+ static Future<WebSocket> upgrade(HttpRequest request,
+ {protocolSelector(List<String> protocols)}) {
+ return _WebSocketTransformerImpl._upgrade(request, protocolSelector);
}
/**
@@ -78,7 +96,7 @@ abstract class WebSocketTransformer
/**
* A two-way HTTP communication object for client or server applications.
*
- * The stream exposes the messages received. A text message will be of type
+ * The stream exposes the messages received. A text message will be of type
* [:String:] and a binary message will be of type [:List<int>:].
*/
abstract class WebSocket implements Stream, StreamSink {
@@ -92,11 +110,11 @@ abstract class WebSocket implements Stream, StreamSink {
/**
* Create a new web socket connection. The URL supplied in [url]
- * must use the scheme [:ws:] or [:wss:]. The [protocols] argument is either
- * a [:String:] or [:List<String>:] specifying the subprotocols the
- * client is willing to speak.
+ * must use the scheme [:ws:] or [:wss:]. The [protocols] argument is
+ * specifying the subprotocols the client is willing to speak.
*/
- static Future<WebSocket> connect(String url, [protocols]) =>
+ static Future<WebSocket> connect(String url,
+ {List<String> protocols: const []}) =>
_WebSocketImpl.connect(url, protocols);
/**
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | sdk/lib/io/websocket_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698