aboutsummaryrefslogtreecommitdiffstats
path: root/test/examples_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-14 17:05:41 +0200
committerLoïc Hoguin <[email protected]>2016-06-14 17:05:41 +0200
commit5003bae369901a6c771075ac4ef600d49b019570 (patch)
treeb4e5b9c9a193c3880732d0addb209ee6f80cc9cb /test/examples_SUITE.erl
parent84fb85e2e4bc91d2dfc0da04674d96db34089a05 (diff)
downloadcowboy-5003bae369901a6c771075ac4ef600d49b019570.tar.gz
cowboy-5003bae369901a6c771075ac4ef600d49b019570.tar.bz2
cowboy-5003bae369901a6c771075ac4ef600d49b019570.zip
Fix eventsource example
Diffstat (limited to 'test/examples_SUITE.erl')
-rw-r--r--test/examples_SUITE.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/examples_SUITE.erl b/test/examples_SUITE.erl
index 6caa7ef..6f651c5 100644
--- a/test/examples_SUITE.erl
+++ b/test/examples_SUITE.erl
@@ -190,6 +190,29 @@ do_echo_post(Transport, Protocol, Config) ->
{ok, <<"this is fun">>} = gun:await_body(ConnPid, Ref),
ok.
+%% Eventsource.
+
+eventsource(Config) ->
+ doc("Eventsource example."),
+ try
+ do_compile_and_start(eventsource),
+ do_eventsource(tcp, http, Config),
+ do_eventsource(tcp, http2, Config)
+ after
+ do_stop(eventsource)
+ end.
+
+do_eventsource(Transport, Protocol, Config) ->
+ ConnPid = gun_open([{port, 8080}, {type, Transport}, {protocol, Protocol}|Config]),
+ Ref = gun:get(ConnPid, "/eventsource"),
+ {response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
+ {_, <<"text/event-stream">>} = lists:keyfind(<<"content-type">>, 1, Headers),
+ %% Receive a few events.
+ {data, nofin, << "id: ", _/bits >>} = gun:await(ConnPid, Ref, 2000),
+ {data, nofin, << "id: ", _/bits >>} = gun:await(ConnPid, Ref, 2000),
+ {data, nofin, << "id: ", _/bits >>} = gun:await(ConnPid, Ref, 2000),
+ gun:close(ConnPid).
+
%% REST Hello World.
rest_hello_world(Config) ->