diff options
author | Loïc Hoguin <[email protected]> | 2012-04-06 22:18:09 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2012-04-06 22:18:09 +0200 |
commit | e8ee64777c133a8bb05a1e6bc449c2c6a4a989db (patch) | |
tree | 258941102f3574a0395b847d0b353f26dc587a95 /test/ws_SUITE.erl | |
parent | 95e05d822f46e791a919f4e966879b4827989669 (diff) | |
parent | 80c67bff33939a14e445ee93e37e8db5778fdfdc (diff) | |
download | cowboy-e8ee64777c133a8bb05a1e6bc449c2c6a4a989db.tar.gz cowboy-e8ee64777c133a8bb05a1e6bc449c2c6a4a989db.tar.bz2 cowboy-e8ee64777c133a8bb05a1e6bc449c2c6a4a989db.zip |
Merge branch 'websocket-fragments' of https://github.com/klaar/cowboy
Diffstat (limited to 'test/ws_SUITE.erl')
-rw-r--r-- | test/ws_SUITE.erl | 63 |
1 files changed, 60 insertions, 3 deletions
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl index 136833f..0c5e2c8 100644 --- a/test/ws_SUITE.erl +++ b/test/ws_SUITE.erl @@ -19,7 +19,7 @@ -export([all/0, groups/0, init_per_suite/1, end_per_suite/1, init_per_group/2, end_per_group/2]). %% ct. -export([ws0/1, ws8/1, ws8_single_bytes/1, ws8_init_shutdown/1, - ws13/1, ws_timeout_hibernate/1]). %% ws. + ws13/1, ws_timeout_hibernate/1, ws_text_fragments/1]). %% ws. %% ct. @@ -28,7 +28,7 @@ all() -> groups() -> BaseTests = [ws0, ws8, ws8_single_bytes, ws8_init_shutdown, ws13, - ws_timeout_hibernate], + ws_timeout_hibernate, ws_text_fragments], [{ws, [], BaseTests}]. init_per_suite(Config) -> @@ -60,7 +60,8 @@ init_dispatch() -> {[<<"localhost">>], [ {[<<"websocket">>], websocket_handler, []}, {[<<"ws_timeout_hibernate">>], ws_timeout_hibernate_handler, []}, - {[<<"ws_init_shutdown">>], websocket_handler_init_shutdown, []} + {[<<"ws_init_shutdown">>], websocket_handler_init_shutdown, []}, + {[<<"ws_echo_handler">>], websocket_echo_handler, []} ]} ]. @@ -310,6 +311,62 @@ ws13(Config) -> {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, + [binary, {active, false}, {packet, raw}]), + ok = gen_tcp:send(Socket, [ + "GET /ws_echo_handler 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: 8\r\n" + "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\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, <<>>] = websocket_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), + + ok = gen_tcp:send(Socket, [ + << 0:1, 0:3, 1:4, 1:1, 5:7 >>, + << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>, + << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>]), + ok = gen_tcp:send(Socket, [ + << 1:1, 0:3, 0:4, 1:1, 5:7 >>, + << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>, + << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>]), + {ok, << 1:1, 0:3, 1:4, 0:1, 10:7, "HelloHello" >>} + = gen_tcp:recv(Socket, 0, 6000), + + ok = gen_tcp:send(Socket, [ + %% #1 + << 0:1, 0:3, 1:4, 1:1, 5:7 >>, + << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>, + << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>, + %% #2 + << 0:1, 0:3, 0:4, 1:1, 5:7 >>, + << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>, + << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>, + %% #3 + << 1:1, 0:3, 0:4, 1:1, 5:7 >>, + << 16#37 >>, << 16#fa >>, << 16#21 >>, << 16#3d >>, << 16#7f >>, + << 16#9f >>, << 16#4d >>, << 16#51 >>, << 16#58 >>]), + {ok, << 1:1, 0:3, 1:4, 0:1, 15:7, "HelloHelloHello" >>} + = gen_tcp:recv(Socket, 0, 6000), + + ok = gen_tcp:send(Socket, << 1:1, 0:3, 8:4, 0:8 >>), %% close + {ok, << 1:1, 0:3, 8:4, 0:8 >>} = gen_tcp:recv(Socket, 0, 6000), + {error, closed} = gen_tcp:recv(Socket, 0, 6000), + ok. + + websocket_headers({ok, http_eoh, Rest}, Acc) -> [Acc, Rest]; websocket_headers({ok, {http_header, _I, Key, _R, Value}, Rest}, Acc) -> |