Skip to content

Commit

Permalink
the send method does not automatically respond with a 101 status
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 8, 2015
1 parent 2b6dabd commit eb71ecd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 21 additions & 1 deletion lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -569,7 +569,7 @@ all of its subscribers.

The WebSocket protocol offers full bi-directional low-latency communication
channels between clients and servers. Receive messages just by subscribing to
events such as L<Mojo::Transaction::WebSocket/"message"> with the method
events such as L<Mojo::Transaction::WebSocket/"message"> with
L<Mojolicious::Controller/"on"> and return them with
L<Mojolicious::Controller/"send">.

Expand Down Expand Up @@ -623,6 +623,26 @@ L<Mojolicious::Controller/"send">.
</body>
</html>

The connection gets established when you respond to the WebSocket handshake
request, which is a normal HTTP C<GET> request, with a C<101> response status,
which happens automatically if you subscribe to an event with
L<Mojolicious::Controller/"on">.

GET /echo HTTP/1.1
Host: 127.0.0.1:3000
User-Agent: 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=

The event L<Mojo::Transaction::WebSocket/"finish"> will be emitted right after
the WebSocket connection has been closed.

Expand Down
3 changes: 1 addition & 2 deletions lib/Mojolicious/Guides/Routing.pod
Expand Up @@ -638,8 +638,7 @@ additional information.

The connection gets established when you respond to the WebSocket handshake
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.
subscribe to an event with L<Mojolicious::Controller/"on">.

GET /echo HTTP/1.1
Host: mojolicio.us
Expand Down

0 comments on commit eb71ecd

Please sign in to comment.