Skip to content

Commit

Permalink
Merge pull request #8 from starbelly/fix-close-connect-in-example
Browse files Browse the repository at this point in the history
Update README and example with working close status.
  • Loading branch information
yurrriq authored Sep 4, 2019
2 parents b68972a + 8e966a0 commit 5153fff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ handle('websocket', [<<"echo_websocket">>], Req, Args) ->
%% Upgrade to a websocket connection.
elli_websocket:upgrade(Req, Args),

%% websocket is closed.
{close, <<>>};
%% websocket is closed:
%% See RFC-6455 (https://tools.ietf.org/html/rfc6455) for a list of
%% valid WS status codes than can be used on a close frame.
%% Note that the second element is the reason and is abitrary but should be meaningful
%% in regards to your server and sub-protocol.
{<<"1000">>, <<"Closed">>};

handle('GET', [<<"echo_websocket">>], _Req, _Args) ->
%% We got a normal request, request was not upgraded.
{200, [], <<"Use an upgrade request">>};
Expand Down
8 changes: 7 additions & 1 deletion src/elli_example_websocket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ init_ws(_, _, _) ->

handle('websocket', [<<"my">>, <<"websocket">>], Req, Args) ->
elli_websocket:upgrade(Req, Args),
{close, <<>>};

%% websocket is closed:
%% See RFC-6455 (https://tools.ietf.org/html/rfc6455) for a list of
%% valid WS status codes than can be used on a close frame.
%% Note that the second element is the reason and is abitrary but should be meaningful
%% in regards to your server and sub-protocol.
{<<"1000">>, <<"Closed">>};

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

0 comments on commit 5153fff

Please sign in to comment.