diff options
Diffstat (limited to 'test/ws_SUITE.erl')
-rw-r--r-- | test/ws_SUITE.erl | 66 |
1 files changed, 33 insertions, 33 deletions
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl index f15c9fe..b4eebf7 100644 --- a/test/ws_SUITE.erl +++ b/test/ws_SUITE.erl @@ -39,14 +39,14 @@ init_per_group(Name = autobahn, Config) -> _ -> {ok, _} = cowboy:start_clear(Name, 100, [{port, 33080}], #{ env => #{dispatch => init_dispatch()}, - compress => true %% @todo Use a separate option for HTTP and Websocket compression. + websocket_compress => true }), Config end; init_per_group(Name = ws, Config) -> cowboy_test:init_http(Name, #{ env => #{dispatch => init_dispatch()}, - compress => true %% @todo Use a separate option for HTTP and Websocket compression. + websocket_compress => true }, Config). end_per_group(Listener, _Config) -> @@ -78,9 +78,9 @@ init_dispatch() -> {close, 1001, <<"some text!">>}, {text, <<"won't be received">>}]} ]}, + {"/ws_subprotocol", ws_subprotocol, []}, {"/ws_timeout_hibernate", ws_timeout_hibernate, []}, - {"/ws_timeout_cancel", ws_timeout_cancel, []}, - {"/ws_subprotocol", ws_subprotocol, []} + {"/ws_timeout_cancel", ws_timeout_cancel, []} ]} ]). @@ -523,6 +523,35 @@ ws_send_many(Config) -> {error, closed} = gen_tcp:recv(Socket, 0, 6000), ok. +ws_subprotocol(Config) -> + {port, Port} = lists:keyfind(port, 1, Config), + {ok, Socket} = gen_tcp:connect("localhost", Port, + [binary, {active, false}, {packet, raw}]), + ok = gen_tcp:send(Socket, [ + "GET /ws_subprotocol HTTP/1.1\r\n" + "Host: localhost\r\n" + "Connection: Upgrade\r\n" + "Upgrade: websocket\r\n" + "Sec-WebSocket-Origin: http://localhost\r\n" + "Sec-WebSocket-Version: 13\r\n" + "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" + "Sec-WebSocket-Protocol: foo, bar\r\n" + "\r\n"]), + {ok, Handshake} = gen_tcp:recv(Socket, 0, 6000), + {ok, {http_response, {1, 1}, 101, "Switching Protocols"}, Rest} + = erlang:decode_packet(http, Handshake, []), + [Headers, <<>>] = do_decode_headers( + erlang:decode_packet(httph, Rest, []), []), + {'Connection', "Upgrade"} = lists:keyfind('Connection', 1, Headers), + {'Upgrade', "websocket"} = lists:keyfind('Upgrade', 1, Headers), + {"sec-websocket-accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="} + = lists:keyfind("sec-websocket-accept", 1, Headers), + {"sec-websocket-protocol", "foo"} + = lists:keyfind("sec-websocket-protocol", 1, Headers), + {ok, << 1:1, 0:3, 8:4, 0:1, 2:7, 1000:16 >>} = gen_tcp:recv(Socket, 0, 6000), + {error, closed} = gen_tcp:recv(Socket, 0, 6000), + ok. + ws_text_fragments(Config) -> {port, Port} = lists:keyfind(port, 1, Config), {ok, Socket} = gen_tcp:connect("localhost", Port, @@ -664,35 +693,6 @@ ws_timeout_reset(Config) -> {error, closed} = gen_tcp:recv(Socket, 0, 6000), ok. -ws_subprotocol(Config) -> - {port, Port} = lists:keyfind(port, 1, Config), - {ok, Socket} = gen_tcp:connect("localhost", Port, - [binary, {active, false}, {packet, raw}]), - ok = gen_tcp:send(Socket, [ - "GET /ws_subprotocol HTTP/1.1\r\n" - "Host: localhost\r\n" - "Connection: Upgrade\r\n" - "Upgrade: websocket\r\n" - "Sec-WebSocket-Origin: http://localhost\r\n" - "Sec-WebSocket-Version: 13\r\n" - "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" - "Sec-WebSocket-Protocol: foo, bar\r\n" - "\r\n"]), - {ok, Handshake} = gen_tcp:recv(Socket, 0, 6000), - {ok, {http_response, {1, 1}, 101, "Switching Protocols"}, Rest} - = erlang:decode_packet(http, Handshake, []), - [Headers, <<>>] = do_decode_headers( - erlang:decode_packet(httph, Rest, []), []), - {'Connection', "Upgrade"} = lists:keyfind('Connection', 1, Headers), - {'Upgrade', "websocket"} = lists:keyfind('Upgrade', 1, Headers), - {"sec-websocket-accept", "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="} - = lists:keyfind("sec-websocket-accept", 1, Headers), - {"sec-websocket-protocol", "foo"} - = lists:keyfind("sec-websocket-protocol", 1, Headers), - {ok, << 1:1, 0:3, 8:4, 0:1, 2:7, 1000:16 >>} = gen_tcp:recv(Socket, 0, 6000), - {error, closed} = gen_tcp:recv(Socket, 0, 6000), - ok. - %% Internal. do_decode_headers({ok, http_eoh, Rest}, Acc) -> |