Skip to content

Commit

Permalink
better Mojo::UserAgent example for tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 11, 2013
1 parent 9263835 commit 7b806e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changes
Expand Up @@ -3,7 +3,8 @@
- Added finished_ok method to Test::Mojo.
- Removed deprecated slurp_rel_file method from Mojo::Home.
- Removed deprecated html_escape function from Mojo::Util.
- Improved Mojo::Transaction::WebSocket with support for status codes.
- Improved Mojo::Transaction::WebSocket with support for status codes and
reasons.
- Improved documentation. (jberger, sri)
- Improved tests.
- Fixed a few small timing bugs in Mojo::Server::Daemon.
Expand Down
5 changes: 2 additions & 3 deletions lib/Mojo/Transaction/WebSocket.pm
Expand Up @@ -11,7 +11,7 @@ use constant DEBUG => $ENV{MOJO_WEBSOCKET_DEBUG} || 0;
use constant MODERN =>
(($Config{use64bitint} // '') eq 'define' || $Config{longsize} >= 8);

# Unique value from the spec
# Unique value from RFC 6455
use constant GUID => '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';

# Opcodes
Expand Down Expand Up @@ -227,7 +227,6 @@ sub server_close {
sub server_handshake {
my $self = shift;

# WebSocket handshake
my $res_headers = $self->res->code(101)->headers;
$res_headers->upgrade('websocket')->connection('Upgrade');
my $req_headers = $self->req->headers;
Expand Down Expand Up @@ -289,7 +288,7 @@ sub _message {
# No FIN bit (Continuation)
return unless $frame->[0];

# Message
# Whole message
my $msg = delete $self->{message};
if (delete $self->{op} == TEXT) {
$self->emit(text => $msg);
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious/Lite.pm
Expand Up @@ -845,9 +845,11 @@ L<Mojo::JSON> and L<Mojo::DOM> this can be a very powerful tool.
use Mojolicious::Lite;
get '/test' => sub {
get '/headers' => sub {
my $self = shift;
$self->render(data => $self->ua->get('http://mojolicio.us')->res->body);
my $url = $self->param('url') || 'http://mojolicio.us';
my $dom = $self->ua->get($url)->res->dom;
$self->render(json => [$dom->find('h1, h2, h3')->pluck('text')->each]);
};
app->start;
Expand Down

0 comments on commit 7b806e9

Please sign in to comment.