aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2017-05-28 19:04:16 +0200
committerLoïc Hoguin <[email protected]>2017-05-28 20:19:39 +0200
commit5f421f93bc36d73161f7aa8705da5ea3a3793807 (patch)
tree3111c6978ec7b562a2fcf0bbe76f09d653dc67ac /test/handlers
parent8cb125dbb7c410cab862aac5a582e5dfa0e46772 (diff)
downloadcowboy-5f421f93bc36d73161f7aa8705da5ea3a3793807.tar.gz
cowboy-5f421f93bc36d73161f7aa8705da5ea3a3793807.tar.bz2
cowboy-5f421f93bc36d73161f7aa8705da5ea3a3793807.zip
Introduce the req_filter Websocket option
This option allows customizing the compacting of the Req object when using Websocket. By default it will keep most public fields excluding headers of course, since those can be large.
Diffstat (limited to 'test/handlers')
-rw-r--r--test/handlers/ws_terminate_h.erl34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/handlers/ws_terminate_h.erl b/test/handlers/ws_terminate_h.erl
new file mode 100644
index 0000000..4621df6
--- /dev/null
+++ b/test/handlers/ws_terminate_h.erl
@@ -0,0 +1,34 @@
+%% This module sends a message with terminate arguments to the test case process.
+
+-module(ws_terminate_h).
+-behavior(cowboy_websocket).
+
+-export([init/2]).
+-export([websocket_init/1]).
+-export([websocket_handle/2]).
+-export([websocket_info/2]).
+-export([terminate/3]).
+
+-record(state, {
+ pid
+}).
+
+init(Req, _) ->
+ Pid = list_to_pid(binary_to_list(cowboy_req:header(<<"x-test-pid">>, Req))),
+ Opts = case cowboy_req:qs(Req) of
+ <<"req_filter">> -> #{req_filter => fun(_) -> filtered end};
+ _ -> #{}
+ end,
+ {cowboy_websocket, Req, #state{pid=Pid}, Opts}.
+
+websocket_init(State) ->
+ {ok, State}.
+
+websocket_handle(_, State) ->
+ {ok, State}.
+
+websocket_info(_, State) ->
+ {ok, State}.
+
+terminate(Reason, Req, #state{pid=Pid}) ->
+ Pid ! {terminate, Reason, Req}.