diff options
author | Loïc Hoguin <[email protected]> | 2018-11-15 18:53:42 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-15 18:53:42 +0100 |
commit | 240da3f2d9bc02611b23c1ea0e7bbe8db9d99cd8 (patch) | |
tree | 7c59e4ebd16731bab4fd9ac5deddb55a7762cf1c /test/handlers | |
parent | fbfec873f6026b858c3604d74d88470ce45f4296 (diff) | |
download | cowboy-240da3f2d9bc02611b23c1ea0e7bbe8db9d99cd8.tar.gz cowboy-240da3f2d9bc02611b23c1ea0e7bbe8db9d99cd8.tar.bz2 cowboy-240da3f2d9bc02611b23c1ea0e7bbe8db9d99cd8.zip |
Add the set_options stream handler command
The first two options to benefit from this are the
cowboy_compress_h options.
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/compress_h.erl | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/test/handlers/compress_h.erl b/test/handlers/compress_h.erl index ffea05f..32830d9 100644 --- a/test/handlers/compress_h.erl +++ b/test/handlers/compress_h.erl @@ -19,7 +19,12 @@ init(Req0, State=reply) -> <<"sendfile">> -> AppFile = code:where_is_file("cowboy.app"), Size = filelib:file_size(AppFile), - cowboy_req:reply(200, #{}, {sendfile, 0, Size, AppFile}, Req0) + cowboy_req:reply(200, #{}, {sendfile, 0, Size, AppFile}, Req0); + <<"set_options_threshold0">> -> + %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. + #{pid := Pid, streamid := StreamID} = Req0, + Pid ! {{Pid, StreamID}, {set_options, #{compress_threshold => 0}}}, + cowboy_req:reply(200, #{}, lists:duplicate(100, $a), Req0) end, {ok, Req, State}; init(Req0, State=stream_reply) -> @@ -52,13 +57,17 @@ init(Req0, State=stream_reply) -> cowboy_req:stream_body({sendfile, 0, Size, AppFile}, fin, Req1), Req1; <<"delayed">> -> - Req1 = cowboy_req:stream_reply(200, Req0), - cowboy_req:stream_body(<<"data: Hello!\r\n\r\n">>, nofin, Req1), - timer:sleep(1000), - cowboy_req:stream_body(<<"data: World!\r\n\r\n">>, nofin, Req1), - timer:sleep(1000), - cowboy_req:stream_body(<<"data: Closing!\r\n\r\n">>, fin, Req1), - Req1 + stream_delayed(Req0); + <<"set_options_buffering_false">> -> + %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. + #{pid := Pid, streamid := StreamID} = Req0, + Pid ! {{Pid, StreamID}, {set_options, #{compress_buffering => false}}}, + stream_delayed(Req0); + <<"set_options_buffering_true">> -> + %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. + #{pid := Pid, streamid := StreamID} = Req0, + Pid ! {{Pid, StreamID}, {set_options, #{compress_buffering => true}}}, + stream_delayed(Req0) end, {ok, Req, State}. @@ -68,3 +77,12 @@ stream_reply(Headers, Req0) -> _ = [cowboy_req:stream_body(Data, nofin, Req) || _ <- lists:seq(1,9)], cowboy_req:stream_body(Data, fin, Req), Req. + +stream_delayed(Req0) -> + Req = cowboy_req:stream_reply(200, Req0), + cowboy_req:stream_body(<<"data: Hello!\r\n\r\n">>, nofin, Req), + timer:sleep(1000), + cowboy_req:stream_body(<<"data: World!\r\n\r\n">>, nofin, Req), + timer:sleep(1000), + cowboy_req:stream_body(<<"data: Closing!\r\n\r\n">>, fin, Req), + Req. |