diff options
author | Benedikt Reinartz <[email protected]> | 2021-07-05 11:53:35 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2022-08-30 14:59:17 +0200 |
commit | 0724dbf536c22fc978ba0bc96052c65f0edafa69 (patch) | |
tree | 16843f327bd6adebf39d69959226aa5ef3db02c2 /test/handlers/sse_clock_close_h.erl | |
parent | 1f42d14e88fe028295a66878140750fee0f93892 (diff) | |
download | gun-0724dbf536c22fc978ba0bc96052c65f0edafa69.tar.gz gun-0724dbf536c22fc978ba0bc96052c65f0edafa69.tar.bz2 gun-0724dbf536c22fc978ba0bc96052c65f0edafa69.zip |
Add tests for the SSE handler
Diffstat (limited to 'test/handlers/sse_clock_close_h.erl')
-rw-r--r-- | test/handlers/sse_clock_close_h.erl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/handlers/sse_clock_close_h.erl b/test/handlers/sse_clock_close_h.erl new file mode 100644 index 0000000..c5911ff --- /dev/null +++ b/test/handlers/sse_clock_close_h.erl @@ -0,0 +1,23 @@ +%% This module implements a loop handler that sends +%% the current time every second using SSE. In contrast +%% to sse_clock_h, this one sends a "Connection: close" +%% header. + +-module(sse_clock_close_h). + +-export([init/2]). +-export([info/3]). + +init(Req, State) -> + self() ! timeout, + {cowboy_loop, cowboy_req:stream_reply(200, #{ + <<"content-type">> => <<"text/event-stream">>, + <<"connection">> => <<"close">> + }, Req), State}. + +info(timeout, Req, State) -> + erlang:send_after(1000, self(), timeout), + cowboy_req:stream_events(#{ + data => cowboy_clock:rfc1123() + }, nofin, Req), + {ok, Req, State}. |