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

Issue 10262031: Add a web socket client (Closed)

Created:
8 years, 7 months ago by Søren Gjesse
Modified:
8 years, 7 months ago
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Add a web socket client The web socket client is a implemented as a class which is created from from a HTTP client connection. This way it is independent from the HTTP client and is just using the HTTP client. The protocol handling is mainly re-using the code from the web socket server. Change the handling of setting an onNoPendingWrites handler on a socket output stream. Now setting a new onNoPendingWrites handler will trigger a callback when there is no pending data to be written. Add socket detaching to the HTTP client as well. Add the ability to get any unparsed data read from the socket for processing after the protocol upgrade. R=ager@google.com, ajohnsen@google.com, vsm@google.com, jacobr@google.com BUG=dart:2001 TEST=tests/standalone/io/web_socket_test.dart Committed: https://code.google.com/p/dart/source/detail?r=7224

Patch Set 1 #

Total comments: 36

Patch Set 2 : Addressed review comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+459 lines, -32 lines) Patch
M runtime/bin/http.dart View 1 3 chunks +25 lines, -2 lines 0 comments Download
M runtime/bin/http_impl.dart View 1 6 chunks +23 lines, -9 lines 0 comments Download
M runtime/bin/http_parser.dart View 3 chunks +5 lines, -0 lines 0 comments Download
M runtime/bin/socket_stream_impl.dart View 1 5 chunks +25 lines, -4 lines 0 comments Download
M runtime/bin/websocket.dart View 1 2 chunks +71 lines, -1 line 0 comments Download
M runtime/bin/websocket_impl.dart View 1 13 chunks +152 lines, -16 lines 0 comments Download
A tests/standalone/io/web_socket_test.dart View 1 1 chunk +158 lines, -0 lines 0 comments Download

Messages

Total messages: 5 (0 generated)
Søren Gjesse
8 years, 7 months ago (2012-05-01 13:53:43 UTC) #1
Anders Johnsen
LGTM http://codereview.chromium.org/10262031/diff/1/runtime/bin/http.dart File runtime/bin/http.dart (right): http://codereview.chromium.org/10262031/diff/1/runtime/bin/http.dart#newcode570 runtime/bin/http.dart:570: class DetachedSocket { The client should never create ...
8 years, 7 months ago (2012-05-02 07:51:57 UTC) #2
Mads Ager (google)
LGTM http://codereview.chromium.org/10262031/diff/1/runtime/bin/http_impl.dart File runtime/bin/http_impl.dart (right): http://codereview.chromium.org/10262031/diff/1/runtime/bin/http_impl.dart#newcode605 runtime/bin/http_impl.dart:605: } else if (_contentLength < 0) { An ...
8 years, 7 months ago (2012-05-02 08:18:17 UTC) #3
Mads Ager (google)
A more high-level comment. We should consider if we can wrap the WebSocketClientConnection in a ...
8 years, 7 months ago (2012-05-02 08:58:27 UTC) #4
Søren Gjesse
8 years, 7 months ago (2012-05-02 10:22:45 UTC) #5
I will try to draft a WebSocket class for presenting the browser API,

http://codereview.chromium.org/10262031/diff/1/runtime/bin/http.dart
File runtime/bin/http.dart (right):

http://codereview.chromium.org/10262031/diff/1/runtime/bin/http.dart#newcode570
runtime/bin/http.dart:570: class DetachedSocket {
On 2012/05/02 07:51:57, ajohnsen wrote:
> The client should never create this object, so I think we should move to
> interface + private implementation.

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/http_impl.dart
File runtime/bin/http_impl.dart (right):

http://codereview.chromium.org/10262031/diff/1/runtime/bin/http_impl.dart#new...
runtime/bin/http_impl.dart:605: } else if (_contentLength < 0) {
On 2012/05/02 08:18:17, Mads Ager wrote:
> An nothing needs to be done here fore _contentLength == 0?

Yes - this was a bug. The spec says:

"The presence of a message-body in a request is signaled by the inclusion of a
Content-Length or Transfer-Encoding header field in the request's
message-headers."

So no body is signaled by having neither Content-Length nor Transfer-Encoding.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/http_impl.dart#new...
runtime/bin/http_impl.dart:773: // TODO(sgjesse): Handle getting the write
handler when using output stream.
On 2012/05/02 08:18:17, Mads Ager wrote:
> Let's file a bug report on this to keep track?

Fixed by setting _socket.outputStream.onNoPendingWrites to null.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/http_impl.dart#new...
runtime/bin/http_impl.dart:1237: // TODO(sgjesse): Needs some state checks.
On 2012/05/02 08:18:17, Mads Ager wrote:
> Either add the checks or file a bug to keep track?

Removed the TODO - not sure which state checks I was thinking about.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/socket_stream_impl...
File runtime/bin/socket_stream_impl.dart (right):

http://codereview.chromium.org/10262031/diff/1/runtime/bin/socket_stream_impl...
runtime/bin/socket_stream_impl.dart:115: _setupWaitOnWrite();
On 2012/05/02 08:18:17, Mads Ager wrote:
> I found the name a bit confusing. How about calling this something like
> _setupWriteHandler?

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/socket_stream_impl...
runtime/bin/socket_stream_impl.dart:199: void _setupWaitOnWrite() {
On 2012/05/02 08:18:17, Mads Ager wrote:
> Can we add a few comments? This sets up a write handler that will write all
> pending data when the underlying socket is ready for more writes.

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket.dart
File runtime/bin/websocket.dart (right):

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket.dart#new...
runtime/bin/websocket.dart:82: WebSocketClientConnection(HttpClientConnection
conn,
On 2012/05/02 07:51:57, ajohnsen wrote:
> Should we add a convenient constructor that just takes a WebSocket url and
maybe
> a HttpHeader object?

After having discussed this off-line we will make a WebSocket class which have
the same interface as the WebSocket in the browser and keep the
WebSocketClientConnection as is.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket.dart#new...
runtime/bin/websocket.dart:101: * received. The type on [message] is either
[:String:] or
On 2012/05/02 08:18:17, Mads Ager wrote:
> The type on -> The type of

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket.dart#new...
runtime/bin/websocket.dart:105: void set onMessage(void callback(message));
On 2012/05/02 07:51:57, ajohnsen wrote:
> Add 'Object' type to match send.

Removed Object from send instead.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket.dart#new...
runtime/bin/websocket.dart:121: void set onNoUpgrade(void
callback(HttpClientResponse request));
On 2012/05/02 07:51:57, ajohnsen wrote:
> request->response.

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket.dart#new...
runtime/bin/websocket.dart:130: * Sends a message. The [message] must be a
[:String:] a
On 2012/05/02 08:18:17, Mads Ager wrote:
> [:String:] or a

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket_impl.dart
File runtime/bin/websocket_impl.dart (right):

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket_impl.dar...
runtime/bin/websocket_impl.dart:560: class _WebSocketConnection extends
_WebSocketConnectionBase implements WebSocketConnection {
On 2012/05/02 08:18:17, Mads Ager wrote:
> Long line.
> 
> What is the reason to have both _WebSocketConnectionBase and
> _WebSocketConnection. There is nothing new here, so can we just rename
> _WebSocketConnectionBase to _WebSocketConnection?

The WebSocketConnectionBase is also used as a base class for
WebSocketClientConnection which have additional implementation. Therefore I did
not want this constructor on the base class for WebSocketClientConnection.

Fixed the long line.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket_impl.dar...
runtime/bin/websocket_impl.dart:628: class _WebSocketClientConnection extends
_WebSocketConnectionBase implements WebSocketClientConnection {
On 2012/05/02 08:18:17, Mads Ager wrote:
> Long line.

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket_impl.dar...
runtime/bin/websocket_impl.dart:655: request.headers.set("Sec-WebSocket-Key",
_generateNonce());
On 2012/05/02 07:51:57, ajohnsen wrote:
> Even though it's not the case, this looks like the nonce is written once and
> then forgotten. Maybe change to a call, then read value from field.

Done.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket_impl.dar...
runtime/bin/websocket_impl.dart:655: request.headers.set("Sec-WebSocket-Key",
_generateNonce());
On 2012/05/02 08:18:17, Mads Ager wrote:
> On 2012/05/02 07:51:57, ajohnsen wrote:
> > Even though it's not the case, this looks like the nonce is written once and
> > then forgotten. Maybe change to a call, then read value from field.
> 
> Or have a getter that calculates on first access and caches.

Changed as Anders suggested.

http://codereview.chromium.org/10262031/diff/1/runtime/bin/websocket_impl.dar...
runtime/bin/websocket_impl.dart:680: _socketReady(detached.socket,
detached.unparsedData);
On 2012/05/02 08:18:17, Mads Ager wrote:
> Instead of picking out the socket and the unparsedData here just pass the
> DetachedSocet to _socketREady? Similarly for the constructors of the
connection.

Done.

http://codereview.chromium.org/10262031/diff/1/tests/standalone/io/web_socket...
File tests/standalone/io/web_socket_test.dart (right):

http://codereview.chromium.org/10262031/diff/1/tests/standalone/io/web_socket...
tests/standalone/io/web_socket_test.dart:26: conn.onError = (e) =>
Expect.fail("Unexpected error $e");
On 2012/05/02 08:18:17, Mads Ager wrote:
> Since the error handler throws by default now we could leave this out. But it
> might be nice to have it explict?

No, not realy - removed.

http://codereview.chromium.org/10262031/diff/1/tests/standalone/io/web_socket...
tests/standalone/io/web_socket_test.dart:36: wsconn.onOpen = () {
On 2012/05/02 08:18:17, Mads Ager wrote:
> Could be a one-liner.

Done.

Powered by Google App Engine
This is Rietveld 408576698