From 5003bae369901a6c771075ac4ef600d49b019570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 14 Jun 2016 17:05:41 +0200 Subject: Fix eventsource example --- test/examples_SUITE.erl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/examples_SUITE.erl') 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) -> -- cgit v1.2.3