Skip to content

Commit

Permalink
allow is_established to be used client-side as well
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 9, 2015
1 parent 4f0399d commit adfe975
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -106,7 +106,7 @@ sub client_challenge {
if ($headers->sec_websocket_extensions // '') =~ /permessage-deflate/;

return _challenge($self->req->headers->sec_websocket_key) eq
$headers->sec_websocket_accept;
$headers->sec_websocket_accept && ++$self->{open};
}

sub client_handshake {
Expand Down
10 changes: 6 additions & 4 deletions t/mojo/websocket.t
Expand Up @@ -161,10 +161,11 @@ ok $body =~ /^(\d+)failed!$/ && $1 == 15, 'right content';

# Server directly sends a message
$result = '';
my ($status, $msg);
my ($established, $status, $msg);
$ua->websocket(
'/early_start' => sub {
my ($ua, $tx) = @_;
$established = $tx->is_established;
$tx->on(
finish => sub {
my ($tx, $code, $reason) = @_;
Expand All @@ -182,9 +183,10 @@ $ua->websocket(
}
);
Mojo::IOLoop->start;
is $status, 1000, 'right status';
is $msg, 'I ♥ Mojolicious!', 'right message';
is $result, 'test0test2test1', 'right result';
ok $established, 'connection established';
is $status, 1000, 'right status';
is $msg, 'I ♥ Mojolicious!', 'right message';
is $result, 'test0test2test1', 'right result';

# Connection denied
($stash, $code, $ws) = ();
Expand Down

0 comments on commit adfe975

Please sign in to comment.