0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-16 13:10:24 +00:00

Add cowboy_req:cast/2

Better than sending messages manually.
This commit is contained in:
Loïc Hoguin 2019-10-07 13:25:49 +02:00
parent 5cdf78fd57
commit 2e8fcb9a9e
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
6 changed files with 105 additions and 49 deletions

View file

@ -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}.