Skip to content

Commit 5153fff

Browse files
authored
Merge pull request #8 from starbelly/fix-close-connect-in-example
Update README and example with working close status.
2 parents b68972a + 8e966a0 commit 5153fff

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ handle('websocket', [<<"echo_websocket">>], Req, Args) ->
118118
%% Upgrade to a websocket connection.
119119
elli_websocket:upgrade(Req, Args),
120120

121-
%% websocket is closed.
122-
{close, <<>>};
121+
%% websocket is closed:
122+
%% See RFC-6455 (https://tools.ietf.org/html/rfc6455) for a list of
123+
%% valid WS status codes than can be used on a close frame.
124+
%% Note that the second element is the reason and is abitrary but should be meaningful
125+
%% in regards to your server and sub-protocol.
126+
{<<"1000">>, <<"Closed">>};
127+
123128
handle('GET', [<<"echo_websocket">>], _Req, _Args) ->
124129
%% We got a normal request, request was not upgraded.
125130
{200, [], <<"Use an upgrade request">>};

src/elli_example_websocket.erl

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ init_ws(_, _, _) ->
5555

5656
handle('websocket', [<<"my">>, <<"websocket">>], Req, Args) ->
5757
elli_websocket:upgrade(Req, Args),
58-
{close, <<>>};
58+
59+
%% websocket is closed:
60+
%% See RFC-6455 (https://tools.ietf.org/html/rfc6455) for a list of
61+
%% valid WS status codes than can be used on a close frame.
62+
%% Note that the second element is the reason and is abitrary but should be meaningful
63+
%% in regards to your server and sub-protocol.
64+
{<<"1000">>, <<"Closed">>};
5965

6066
handle('GET', [<<"my">>, <<"websocket">>], _Req, _Args) ->
6167
{200, [], <<"Use an upgrade request">>};

0 commit comments

Comments
 (0)