Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added no_compression method to Mojo::Transaction::WebSocket
  • Loading branch information
kraih committed May 15, 2014
1 parent 46de638 commit 94b9cfe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -5,6 +5,7 @@
with user expectations.
- Removed deprecated support for "X-Forwarded-HTTPS".
- Removed generate_port method from Mojo::IOLoop.
- Added no_compression method to Mojo::Transaction::WebSocket.
- Fixed Mojo::IOLoop::Server to work correctly with newer versions of
IO::Socket::SSL. (noxxi)
- Fixed warnings in Mojo::IOLoop::Delay.
Expand Down
11 changes: 11 additions & 0 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -156,6 +156,10 @@ sub new {
return $self;
}

sub no_compression {
shift->compressed(0)->res->headers->remove('Sec-WebSocket-Extensions');
}

sub parse_frame {
my ($self, $buffer) = @_;

Expand Down Expand Up @@ -615,6 +619,13 @@ Construct a new L<Mojo::Transaction::WebSocket> object and subscribe to
L</"frame"> event with default message parser, which also handles C<PING> and
C<CLOSE> frames automatically.
=head2 no_compression
$ws->no_compression;
Make sure C<permessage-deflate> extension is deactivated for this WebSocket
connection.
=head2 parse_frame
my $frame = $ws->parse_frame(\$bytes);
Expand Down
6 changes: 2 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -570,14 +570,12 @@ L<Mojolicious::Controller/"send">.
The event L<Mojo::Transaction::WebSocket/"finish"> will be emitted right after
the WebSocket connection has been closed.

$self->tx->compressed(0);
$self->res->headers->remove('Sec-WebSocket-Extensions');
$self->tx->no_compression;

By default C<permessage-deflate> compression will be used if the client
supports it, this can result in much better performance, but also increases
memory usage by up to 300KB per connection. It can be disabled with
L<Mojo::Transaction::WebSocket/"compressed"> and by removing the
C<Sec-WebSocket-Extensions> header from the WebSocket handshake response.
L<Mojo::Transaction::WebSocket/"no_compression">.

=head2 Testing WebSocket web services

Expand Down
3 changes: 1 addition & 2 deletions t/mojolicious/websocket_lite_app.t
Expand Up @@ -27,8 +27,7 @@ get '/echo' => {text => 'plain echo!'};

websocket '/no_compression' => sub {
my $self = shift;
$self->tx->compressed(0);
$self->res->headers->remove('Sec-WebSocket-Extensions');
$self->tx->no_compression;
$self->on(binary => sub { shift->send({binary => shift}) });
};

Expand Down

0 comments on commit 94b9cfe

Please sign in to comment.