From 29d347bf5bed001ae8d8763e6af53950c190de40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 6 Aug 2018 15:16:01 +0200 Subject: Rewrite the SSE suite using Cowboy --- test/handlers/sse_clock_h.erl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/handlers/sse_clock_h.erl (limited to 'test/handlers') diff --git a/test/handlers/sse_clock_h.erl b/test/handlers/sse_clock_h.erl new file mode 100644 index 0000000..23b834f --- /dev/null +++ b/test/handlers/sse_clock_h.erl @@ -0,0 +1,21 @@ +%% This module implements a loop handler that sends +%% the current time every second using SSE. + +-module(sse_clock_h). + +-export([init/2]). +-export([info/3]). + +init(Req, State) -> + self() ! timeout, + {cowboy_loop, cowboy_req:stream_reply(200, #{ + <<"content-type">> => <<"text/event-stream">> + }, Req), State}. + +info(timeout, Req, State) -> + erlang:send_after(1000, self(), timeout), + Time = calendar:system_time_to_rfc3339(erlang:system_time(second)), + cowboy_req:stream_events(#{ + data => Time + }, nofin, Req), + {ok, Req, State}. -- cgit v1.2.3