aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-16 13:48:15 +0100
committerLoïc Hoguin <[email protected]>2018-11-16 13:49:00 +0100
commitf5015cb14bbadef95285460f3d842fbbb05c33c3 (patch)
tree6b0b633c22c4a2fb49256da63ca4f91a31f5ad8e /test/handlers
parent75045637fc6026054900f2dbea75805ad7c8e682 (diff)
downloadcowboy-f5015cb14bbadef95285460f3d842fbbb05c33c3.tar.gz
cowboy-f5015cb14bbadef95285460f3d842fbbb05c33c3.tar.bz2
cowboy-f5015cb14bbadef95285460f3d842fbbb05c33c3.zip
Add the set_options Websocket command
It allows overriding the idle_timeout option only for now.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/ws_set_options_commands_h.erl20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/handlers/ws_set_options_commands_h.erl b/test/handlers/ws_set_options_commands_h.erl
new file mode 100644
index 0000000..88d4e72
--- /dev/null
+++ b/test/handlers/ws_set_options_commands_h.erl
@@ -0,0 +1,20 @@
+%% This module sets options based on the frame received.
+
+-module(ws_set_options_commands_h).
+-behavior(cowboy_websocket).
+
+-export([init/2]).
+-export([websocket_handle/2]).
+-export([websocket_info/2]).
+
+init(Req, RunOrHibernate) ->
+ {cowboy_websocket, Req, RunOrHibernate,
+ #{idle_timeout => infinity}}.
+
+websocket_handle(Frame={text, <<"idle_timeout_short">>}, State=run) ->
+ {[{set_options, #{idle_timeout => 500}}, Frame], State};
+websocket_handle(Frame={text, <<"idle_timeout_short">>}, State=hibernate) ->
+ {[{set_options, #{idle_timeout => 500}}, Frame], State, hibernate}.
+
+websocket_info(_Info, State) ->
+ {[], State}.