diff options
author | Loïc Hoguin <[email protected]> | 2018-11-16 12:54:34 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-11-16 12:54:34 +0100 |
commit | 1949357f0cbcc1e6c94add457c7cad90d35340c1 (patch) | |
tree | b1bebfd726e71fbe34635e6ca5aacebb62f508ac /test/handlers/set_options_h.erl | |
parent | 240da3f2d9bc02611b23c1ea0e7bbe8db9d99cd8 (diff) | |
download | cowboy-1949357f0cbcc1e6c94add457c7cad90d35340c1.tar.gz cowboy-1949357f0cbcc1e6c94add457c7cad90d35340c1.tar.bz2 cowboy-1949357f0cbcc1e6c94add457c7cad90d35340c1.zip |
Allow overriding cowboy_http's idle_timeout per request
This allows requests that expect to run longer to do so
without impacting the configuration of other requests.
Diffstat (limited to 'test/handlers/set_options_h.erl')
-rw-r--r-- | test/handlers/set_options_h.erl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/handlers/set_options_h.erl b/test/handlers/set_options_h.erl new file mode 100644 index 0000000..a26bb98 --- /dev/null +++ b/test/handlers/set_options_h.erl @@ -0,0 +1,22 @@ +%% This module sets options dynamically and performs +%% some related relevant operation for testing the change. + +-module(set_options_h). + +-export([init/2]). + +init(Req, State) -> + set_options(cowboy_req:binding(key, Req), 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}}}, + {_, 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}}}, + {_, Body, Req} = cowboy_req:read_body(Req0), + {ok, cowboy_req:reply(200, #{}, Body, Req), State}. |