diff options
Diffstat (limited to 'test/handlers')
-rw-r--r-- | test/handlers/delayed_hello_h.erl | 11 | ||||
-rw-r--r-- | test/handlers/delayed_push_h.erl | 13 | ||||
-rw-r--r-- | test/handlers/ws_frozen_h.erl | 23 | ||||
-rw-r--r-- | test/handlers/ws_timeout_close_h.erl | 25 |
4 files changed, 72 insertions, 0 deletions
diff --git a/test/handlers/delayed_hello_h.erl b/test/handlers/delayed_hello_h.erl new file mode 100644 index 0000000..68ef1ad --- /dev/null +++ b/test/handlers/delayed_hello_h.erl @@ -0,0 +1,11 @@ +%% Feel free to use, reuse and abuse the code in this file. + +-module(delayed_hello_h). + +-export([init/2]). + +init(Req, Timeout) -> + timer:sleep(Timeout), + {ok, cowboy_req:reply(200, #{ + <<"content-type">> => <<"text/plain">> + }, <<"Hello world!">>, Req), Timeout}. diff --git a/test/handlers/delayed_push_h.erl b/test/handlers/delayed_push_h.erl new file mode 100644 index 0000000..dbb8e56 --- /dev/null +++ b/test/handlers/delayed_push_h.erl @@ -0,0 +1,13 @@ +%% Feel free to use, reuse and abuse the code in this file. + +-module(delayed_push_h). + +-export([init/2]). + +init(Req, Timeout) -> + timer:sleep(Timeout), + cowboy_req:push("/", #{<<"accept">> => <<"text/plain">>}, Req), + cowboy_req:push("/empty", #{<<"accept">> => <<"text/plain">>}, Req), + {ok, cowboy_req:reply(200, #{ + <<"content-type">> => <<"text/plain">> + }, <<"Hello world!">>, Req), Timeout}. diff --git a/test/handlers/ws_frozen_h.erl b/test/handlers/ws_frozen_h.erl new file mode 100644 index 0000000..bac77c2 --- /dev/null +++ b/test/handlers/ws_frozen_h.erl @@ -0,0 +1,23 @@ +%% Feel free to use, reuse and abuse the code in this file. + +-module(ws_frozen_h). + +-export([init/2]). +-export([websocket_init/1]). +-export([websocket_handle/2]). +-export([websocket_info/2]). + +init(Req, State) -> + {cowboy_websocket, Req, State, #{ + compress => true + }}. + +websocket_init(Timeout) -> + timer:sleep(Timeout), + {ok, undefined}. + +websocket_handle(_Frame, State) -> + {[], State}. + +websocket_info(_Info, State) -> + {[], State}. diff --git a/test/handlers/ws_timeout_close_h.erl b/test/handlers/ws_timeout_close_h.erl new file mode 100644 index 0000000..6fef168 --- /dev/null +++ b/test/handlers/ws_timeout_close_h.erl @@ -0,0 +1,25 @@ +%% Feel free to use, reuse and abuse the code in this file. + +-module(ws_timeout_close_h). + +-export([init/2]). +-export([websocket_init/1]). +-export([websocket_handle/2]). +-export([websocket_info/2]). + +init(Req, State) -> + {cowboy_websocket, Req, State, #{ + compress => true + }}. + +websocket_init(Timeout) -> + _ = erlang:send_after(Timeout, self(), timeout_close), + {[], undefined}. + +websocket_handle(_Frame, State) -> + {[], State}. + +websocket_info(timeout_close, State) -> + {[{close, 3333, <<>>}], State}; +websocket_info(_Info, State) -> + {[], State}. |