Skip to content

Commit

Permalink
show actual WebSocket handshake in the routing guide
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 3, 2015
1 parent 8efa1e4 commit 054a265
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -1117,10 +1117,11 @@ work inside an already running event loop or start one on demand.

WebSockets are not just for the server-side, you can use
L<Mojo::UserAgent/"websocket"> to open new connections, which are always
non-blocking. The handshake is a normal HTTP request with a few additional
headers, it can even contain cookies, followed by a C<101> response from the
server notifying our user agent that the connection has been established and
it can start using the bi-directional WebSocket protocol.
non-blocking. The WebSocket handshake uses HTTP, and is a normal C<GET>
request with a few additional headers. It can even contain cookies, and is
followed by a C<101> response from the server, notifying our user agent that
the connection has been established and it can start using the bi-directional
WebSocket protocol.

use Mojo::UserAgent;
use Mojo::IOLoop;
Expand Down
15 changes: 15 additions & 0 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -629,6 +629,21 @@ request with a C<101> response status, which happens automatically if you
subscribe to an event with L<Mojolicious::Controller/"on"> or send a message
with L<Mojolicious::Controller/"send"> right away.

GET /echo HTTP/1.1
Host: mojolicio.us
User-Agent: Mozilla/5.0 (compatible; Mojolicious; Perl)
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Key: IDM3ODE4NDk2MjA1OTcxOQ==
Sec-WebSocket-Version: 13

HTTP/1.1 101 Switching Protocols
Server: Mojolicious (Perl)
Date: Tue, 03 Feb 2015 17:08:24 GMT
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Accept: SWsp5N2iNxPbHlcOTIw8ERvyVPY=

=head2 Catch-all route

Since routes match in the order in which they were defined, you can catch all
Expand Down

0 comments on commit 054a265

Please sign in to comment.