Skip to content

Commit

Permalink
fixed WebSocket cookie bug in Mojo::UserAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 11, 2013
1 parent a7f4185 commit 8e13768
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,7 +1,8 @@

3.77 2013-01-11
- Improved tests.
- Fixed localization bug in Mojo::EventEmitter.
- Fixed aliasing bug in Mojo::EventEmitter.
- Fixed WebSocket cookie bug in Mojo::UserAgent.
- Fixed small upgrade bugs in Mojo::UserAgent::Transactor.

3.76 2013-01-10
Expand Down
1 change: 1 addition & 0 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -335,6 +335,7 @@ sub _handle {

# Upgrade connection to WebSocket
elsif ($old && (my $new = $self->_upgrade($id))) {
if (my $jar = $self->cookie_jar) { $jar->extract($old) }
$old->client_close;
$self->_finish($new, $c->{cb});
$new->client_read($old->res->leftovers);
Expand Down
8 changes: 7 additions & 1 deletion t/mojolicious/websocket_lite_app.t
Expand Up @@ -81,10 +81,12 @@ under '/nested';
# WebSocket /nested
websocket sub {
my $self = shift;
my $echo = $self->cookie('echo') // '';
$self->cookie(echo => 'again');
$self->on(
message => sub {
my ($self, $msg) = @_;
$self->send("nested echo: $msg");
$self->send("nested echo: $msg$echo");
}
);
};
Expand Down Expand Up @@ -181,6 +183,10 @@ $t->websocket_ok('/once')->send_ok('hello')->message_is('ONE: hello')
$t->websocket_ok('/nested')->send_ok('hello')
->message_is('nested echo: hello')->finish_ok;

# WebSocket /nested (with cookie)
$t->websocket_ok('/nested')->send_ok('hello')
->message_is('nested echo: helloagain')->finish_ok;

# GET /nested (plain alternative)
$t->get_ok('/nested')->status_is(200)->content_is('plain nested!');

Expand Down

0 comments on commit 8e13768

Please sign in to comment.