Debian Codegraph @

test/handlers/set_options_h.erl

raw
1 %% This module sets options dynamically and performs
2 %% some related relevant operation for testing the change.
3
4 -module(set_options_h).
5
6 -export([init/2]).
7
8 init(Req, State) ->
9 set_options(cowboy_req:binding(key, Req), Req, State).
10
11 set_options(<<"chunked_false">>, Req0, State) ->
12 cowboy_req:cast({set_options, #{chunked => false}}, Req0),
13 Req = cowboy_req:stream_reply(200, Req0),
14 cowboy_req:stream_body(<<0:8000000>>, fin, Req),
15 {ok, Req, State};
16 set_options(<<"chunked_false_ignored">>, Req0, State) ->
17 cowboy_req:cast({set_options, #{chunked => false}}, Req0),
18 Req = cowboy_req:reply(200, #{}, <<"Hello world!">>, Req0),
19 {ok, Req, State};
20 set_options(<<"idle_timeout_short">>, Req0, State) ->
21 cowboy_req:cast({set_options, #{idle_timeout => 500}}, Req0),
22 {_, Body, Req} = cowboy_req:read_body(Req0),
23 {ok, cowboy_req:reply(200, #{}, Body, Req), State};
24 set_options(<<"idle_timeout_long">>, Req0, State) ->
25 cowboy_req:cast({set_options, #{idle_timeout => 60000}}, Req0),
26 {_, Body, Req} = cowboy_req:read_body(Req0),
27 {ok, cowboy_req:reply(200, #{}, Body, Req), State};
28 set_options(<<"metrics_user_data">>, Req, State) ->
29 cowboy_req:cast({set_options, #{metrics_user_data => #{handler => ?MODULE}}}, Req),
30 {ok, cowboy_req:reply(200, #{}, <<"Hello world!">>, Req), State}.