From f104da9322f83361e5bdb8bec0f396f8ad824798 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= <essen@ninenines.eu>
Date: Fri, 13 Oct 2017 23:20:49 +0200
Subject: Small guide fixes

---
 doc/src/guide/ws_handlers.asciidoc | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

(limited to 'doc/src/guide/ws_handlers.asciidoc')

diff --git a/doc/src/guide/ws_handlers.asciidoc b/doc/src/guide/ws_handlers.asciidoc
index 84dfb9b..a79d7e2 100644
--- a/doc/src/guide/ws_handlers.asciidoc
+++ b/doc/src/guide/ws_handlers.asciidoc
@@ -57,18 +57,19 @@ be:
 
 [source,erlang]
 ----
-init(Req, State) ->
-    case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req) of
+init(Req0, State) ->
+    case cowboy_req:parse_header(<<"sec-websocket-protocol">>, Req0) of
         undefined ->
-            {cowboy_websocket, Req, State};
+            {cowboy_websocket, Req0, State};
         Subprotocols ->
             case lists:keymember(<<"mqtt">>, 1, Subprotocols) of
                 true ->
-                    Req2 = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>,
-                        <<"mqtt">>, Req),
-                    {cowboy_websocket, Req2, State};
+                    Req = cowboy_req:set_resp_header(<<"sec-websocket-protocol">>,
+                        <<"mqtt">>, Req0),
+                    {cowboy_websocket, Req, State};
                 false ->
-                    {stop, Req, State}
+                    Req = cowboy_req:reply(400, Req0),
+                    {ok, Req, State}
             end
     end.
 ----
-- 
cgit v1.2.3

