aboutsummaryrefslogtreecommitdiffstats
path: root/test/examples_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-13 18:10:33 +0200
committerLoïc Hoguin <[email protected]>2016-06-13 18:10:33 +0200
commita4fb56018ec396e4d889f76cf7ef5c73fbe82cc1 (patch)
treece41dd184e86b4c403204ceaad18bc0dfa7f117b /test/examples_SUITE.erl
parent352cfce6635fde32348173110f35539bb8459d3f (diff)
downloadcowboy-a4fb56018ec396e4d889f76cf7ef5c73fbe82cc1.tar.gz
cowboy-a4fb56018ec396e4d889f76cf7ef5c73fbe82cc1.tar.bz2
cowboy-a4fb56018ec396e4d889f76cf7ef5c73fbe82cc1.zip
Fix websocket example
Diffstat (limited to 'test/examples_SUITE.erl')
-rw-r--r--test/examples_SUITE.erl29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/examples_SUITE.erl b/test/examples_SUITE.erl
index 096be02..42d0be8 100644
--- a/test/examples_SUITE.erl
+++ b/test/examples_SUITE.erl
@@ -249,3 +249,32 @@ do_markdown_middleware(Transport, Protocol, Config) ->
{200, Headers, <<"<h1>", _/bits >>} = do_get(Transport, Protocol, "/video.html", Config),
{_, <<"text/html">>} = lists:keyfind(<<"content-type">>, 1, Headers),
ok.
+
+%% Websocket.
+
+websocket(_) ->
+ doc("Websocket example."),
+ try
+ do_compile_and_start(websocket),
+ %% We can only initiate a Websocket connection from HTTP/1.1.
+ {ok, Pid} = gun:open("127.0.0.1", 8080, #{protocols => [http], retry => 0}),
+ {ok, http} = gun:await_up(Pid),
+ _ = monitor(process, Pid),
+ gun:ws_upgrade(Pid, "/websocket", [], #{compress => true}),
+ receive
+ {gun_ws_upgrade, Pid, ok, _} ->
+ ok;
+ Msg1 ->
+ exit({connection_failed, Msg1})
+ end,
+ gun:ws_send(Pid, {text, <<"hello">>}),
+ receive
+ {gun_ws, Pid, {text, <<"That's what she said! hello">>}} ->
+ ok;
+ Msg2 ->
+ exit({receive_failed, Msg2})
+ end,
+ gun:ws_send(Pid, close)
+ after
+ do_stop(websocket)
+ end.