aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/ws_active_commands_h.erl4
-rw-r--r--test/handlers/ws_deflate_commands_h.erl24
2 files changed, 26 insertions, 2 deletions
diff --git a/test/handlers/ws_active_commands_h.erl b/test/handlers/ws_active_commands_h.erl
index 4cdb3b1..1c615e3 100644
--- a/test/handlers/ws_active_commands_h.erl
+++ b/test/handlers/ws_active_commands_h.erl
@@ -1,5 +1,5 @@
-%% This module takes commands from the x-commands header
-%% and returns them in the websocket_init/1 callback.
+%% This module starts with active mode disabled
+%% and enables it again once a timeout is triggered.
-module(ws_active_commands_h).
-behavior(cowboy_websocket).
diff --git a/test/handlers/ws_deflate_commands_h.erl b/test/handlers/ws_deflate_commands_h.erl
new file mode 100644
index 0000000..14236bc
--- /dev/null
+++ b/test/handlers/ws_deflate_commands_h.erl
@@ -0,0 +1,24 @@
+%% This module enables/disables compression
+%% every time it echoes a frame.
+
+-module(ws_deflate_commands_h).
+-behavior(cowboy_websocket).
+
+-export([init/2]).
+-export([websocket_handle/2]).
+-export([websocket_info/2]).
+
+init(Req, RunOrHibernate) ->
+ {cowboy_websocket, Req,
+ #{deflate => true, hibernate => RunOrHibernate},
+ #{compress => true}}.
+
+websocket_handle(Frame, State=#{deflate := Deflate0, hibernate := run}) ->
+ Deflate = not Deflate0,
+ {[Frame, {deflate, Deflate}], State#{deflate => Deflate}};
+websocket_handle(Frame, State=#{deflate := Deflate0, hibernate := hibernate}) ->
+ Deflate = not Deflate0,
+ {[Frame, {deflate, Deflate}], State#{deflate => Deflate}, hibernate}.
+
+websocket_info(_Info, State) ->
+ {[], State}.