diff options
author | Loïc Hoguin <[email protected]> | 2018-08-06 15:16:01 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-08-06 15:16:01 +0200 |
commit | 29d347bf5bed001ae8d8763e6af53950c190de40 (patch) | |
tree | 347663d67e47ced5994fbeb5ad5bdd68330a7a29 /test/handlers | |
parent | 820456b71fd3ce61df9d5f32280f42cf871ea80b (diff) | |
download | gun-29d347bf5bed001ae8d8763e6af53950c190de40.tar.gz gun-29d347bf5bed001ae8d8763e6af53950c190de40.tar.bz2 gun-29d347bf5bed001ae8d8763e6af53950c190de40.zip |
Rewrite the SSE suite using Cowboy
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/sse_clock_h.erl | 21 |
1 files changed, 21 insertions, 0 deletions
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}. |