set_options_h.erl 912 B

12345678910111213141516171819202122
  1. %% This module sets options dynamically and performs
  2. %% some related relevant operation for testing the change.
  3. -module(set_options_h).
  4. -export([init/2]).
  5. init(Req, State) ->
  6. set_options(cowboy_req:binding(key, Req), Req, State).
  7. set_options(<<"idle_timeout_short">>, Req0, State) ->
  8. %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast.
  9. #{pid := Pid, streamid := StreamID} = Req0,
  10. Pid ! {{Pid, StreamID}, {set_options, #{idle_timeout => 500}}},
  11. {_, Body, Req} = cowboy_req:read_body(Req0),
  12. {ok, cowboy_req:reply(200, #{}, Body, Req), State};
  13. set_options(<<"idle_timeout_long">>, Req0, State) ->
  14. %% @todo This should be replaced by a cowboy_req:cast/cowboy_stream:cast.
  15. #{pid := Pid, streamid := StreamID} = Req0,
  16. Pid ! {{Pid, StreamID}, {set_options, #{idle_timeout => 60000}}},
  17. {_, Body, Req} = cowboy_req:read_body(Req0),
  18. {ok, cowboy_req:reply(200, #{}, Body, Req), State}.