diff options
author | Loïc Hoguin <[email protected]> | 2019-10-07 13:25:49 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2019-10-07 13:25:49 +0200 |
commit | 2e8fcb9a9ef9ef9beff25ed4d48cf0d90609a69b (patch) | |
tree | 96193a4e156389d67172cde5894d70a5e0395d91 /test/handlers | |
parent | 5cdf78fd570a5239a83e8dce3705e53a08c47f7e (diff) | |
download | cowboy-2e8fcb9a9ef9ef9beff25ed4d48cf0d90609a69b.tar.gz cowboy-2e8fcb9a9ef9ef9beff25ed4d48cf0d90609a69b.tar.bz2 cowboy-2e8fcb9a9ef9ef9beff25ed4d48cf0d90609a69b.zip |
Add cowboy_req:cast/2
Better than sending messages manually.
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/compress_h.erl | 12 | ||||
-rw-r--r-- | test/handlers/set_options_h.erl | 20 |
2 files changed, 8 insertions, 24 deletions
diff --git a/test/handlers/compress_h.erl b/test/handlers/compress_h.erl index 76c2db1..27edbd3 100644 --- a/test/handlers/compress_h.erl +++ b/test/handlers/compress_h.erl @@ -24,9 +24,7 @@ init(Req0, State=reply) -> Size = filelib:file_size(AppFile), 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:cast({set_options, #{compress_threshold => 0}}, Req0), cowboy_req:reply(200, #{}, lists:duplicate(100, $a), Req0) end, {ok, Req, State}; @@ -62,14 +60,10 @@ init(Req0, State=stream_reply) -> <<"delayed">> -> 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}}}, + cowboy_req:cast({set_options, #{compress_buffering => false}}, Req0), 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}}}, + cowboy_req:cast({set_options, #{compress_buffering => true}}, Req0), stream_delayed(Req0) end, {ok, Req, State}. diff --git a/test/handlers/set_options_h.erl b/test/handlers/set_options_h.erl index ef88a6f..420b3f9 100644 --- a/test/handlers/set_options_h.erl +++ b/test/handlers/set_options_h.erl @@ -9,32 +9,22 @@ init(Req, State) -> set_options(cowboy_req:binding(key, Req), Req, State). set_options(<<"chunked_false">>, Req0, State) -> - %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. - #{pid := Pid, streamid := StreamID} = Req0, - Pid ! {{Pid, StreamID}, {set_options, #{chunked => false}}}, + cowboy_req:cast({set_options, #{chunked => false}}, Req0), Req = cowboy_req:stream_reply(200, Req0), cowboy_req:stream_body(<<0:8000000>>, fin, Req), {ok, Req, State}; set_options(<<"chunked_false_ignored">>, Req0, State) -> - %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. - #{pid := Pid, streamid := StreamID} = Req0, - Pid ! {{Pid, StreamID}, {set_options, #{chunked => false}}}, + cowboy_req:cast({set_options, #{chunked => false}}, Req0), Req = cowboy_req:reply(200, #{}, <<"Hello world!">>, Req0), {ok, Req, State}; set_options(<<"idle_timeout_short">>, Req0, State) -> - %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. - #{pid := Pid, streamid := StreamID} = Req0, - Pid ! {{Pid, StreamID}, {set_options, #{idle_timeout => 500}}}, + cowboy_req:cast({set_options, #{idle_timeout => 500}}, Req0), {_, Body, Req} = cowboy_req:read_body(Req0), {ok, cowboy_req:reply(200, #{}, Body, Req), State}; set_options(<<"idle_timeout_long">>, Req0, State) -> - %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. - #{pid := Pid, streamid := StreamID} = Req0, - Pid ! {{Pid, StreamID}, {set_options, #{idle_timeout => 60000}}}, + cowboy_req:cast({set_options, #{idle_timeout => 60000}}, Req0), {_, Body, Req} = cowboy_req:read_body(Req0), {ok, cowboy_req:reply(200, #{}, Body, Req), State}; set_options(<<"metrics_user_data">>, Req, State) -> - %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast. - #{pid := Pid, streamid := StreamID} = Req, - Pid ! {{Pid, StreamID}, {set_options, #{metrics_user_data => #{handler => ?MODULE}}}}, + cowboy_req:cast({set_options, #{metrics_user_data => #{handler => ?MODULE}}}, Req), {ok, cowboy_req:reply(200, #{}, <<"Hello world!">>, Req), State}. |