diff options
author | Loïc Hoguin <[email protected]> | 2018-06-27 13:40:11 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-06-27 13:40:11 +0200 |
commit | 0fb68ec07fa8096ecbc124896b56297fad818ae0 (patch) | |
tree | 27b61b3ae2fcff6da09450242a22f18cb3537c5b /test/handlers | |
parent | faefb634de2874cafaf7f2d7fb7d4f8eab9019a9 (diff) | |
download | cowboy-0fb68ec07fa8096ecbc124896b56297fad818ae0.tar.gz cowboy-0fb68ec07fa8096ecbc124896b56297fad818ae0.tar.bz2 cowboy-0fb68ec07fa8096ecbc124896b56297fad818ae0.zip |
Add test cases for cowboy_req:stream_events
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/resp_h.erl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/test/handlers/resp_h.erl b/test/handlers/resp_h.erl index e924c89..625a2ea 100644 --- a/test/handlers/resp_h.erl +++ b/test/handlers/resp_h.erl @@ -246,6 +246,58 @@ do(<<"stream_body_content_length">>, Req0, Opts) -> cowboy_req:stream_body(<<"Hello">>, nofin, Req), {ok, Req, Opts} end; +do(<<"stream_events">>, Req0, Opts) -> + case cowboy_req:binding(arg, Req0) of + %%<<"single">> + %%<<"list">> + <<"single">> -> + Req = cowboy_req:stream_reply(200, + #{<<"content-type">> => <<"text/event-stream">>}, + Req0), + cowboy_req:stream_events(#{ + event => <<"add_comment">>, + data => <<"Comment text.\nWith many lines.">> + }, fin, Req), + {ok, Req, Opts}; + <<"list">> -> + Req = cowboy_req:stream_reply(200, + #{<<"content-type">> => <<"text/event-stream">>}, + Req0), + cowboy_req:stream_events([ + #{ + event => <<"add_comment">>, + data => <<"Comment text.\nWith many lines.">> + }, + #{ + comment => <<"Set retry higher\nwith many lines also.">>, + retry => 10000 + }, + #{ + id => <<"123">>, + event => <<"add_comment">>, + data => <<"Closing!">> + } + ], fin, Req), + {ok, Req, Opts}; + <<"multiple">> -> + Req = cowboy_req:stream_reply(200, + #{<<"content-type">> => <<"text/event-stream">>}, + Req0), + cowboy_req:stream_events(#{ + event => <<"add_comment">>, + data => <<"Comment text.\nWith many lines.">> + }, nofin, Req), + cowboy_req:stream_events(#{ + comment => <<"Set retry higher\nwith many lines also.">>, + retry => 10000 + }, nofin, Req), + cowboy_req:stream_events(#{ + id => <<"123">>, + event => <<"add_comment">>, + data => <<"Closing!">> + }, fin, Req), + {ok, Req, Opts} + end; do(<<"stream_trailers">>, Req0, Opts) -> case cowboy_req:binding(arg, Req0) of <<"large">> -> |