aboutsummaryrefslogtreecommitdiffstats
path: root/test/websocket_handler.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-04-14 21:21:17 +0200
committerLoïc Hoguin <[email protected]>2011-04-14 21:21:17 +0200
commitcb60d18e823e27084e43a64a853bd549efd6784a (patch)
tree7cf3f7e359c80b34e7658024be0b02a1c94d29ef /test/websocket_handler.erl
parent7f35f693fcdd0d174e26f8ff68865ca94bd002d3 (diff)
downloadcowboy-cb60d18e823e27084e43a64a853bd549efd6784a.tar.gz
cowboy-cb60d18e823e27084e43a64a853bd549efd6784a.tar.bz2
cowboy-cb60d18e823e27084e43a64a853bd549efd6784a.zip
Initial draft-hixie-thewebsocketprotocol-76 support.
Diffstat (limited to 'test/websocket_handler.erl')
-rw-r--r--test/websocket_handler.erl29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/websocket_handler.erl b/test/websocket_handler.erl
new file mode 100644
index 0000000..8e6915b
--- /dev/null
+++ b/test/websocket_handler.erl
@@ -0,0 +1,29 @@
+%% Feel free to use, reuse and abuse the code in this file.
+
+-module(websocket_handler).
+-behaviour(cowboy_http_handler).
+-behaviour(cowboy_http_websocket_handler).
+-export([init/3, handle/2, terminate/2]).
+-export([websocket_init/3, websocket_handle/3, websocket_terminate/3]).
+
+init(_Any, _Req, _Opts) ->
+ {upgrade, protocol, cowboy_http_websocket}.
+
+handle(_Req, _State) ->
+ exit(badarg).
+
+terminate(_Req, _State) ->
+ exit(badarg).
+
+websocket_init(_TransportName, Req, _Opts) ->
+ erlang:start_timer(1000, self(), <<"websocket_init">>),
+ {ok, Req, undefined}.
+
+websocket_handle({timeout, _Ref, Msg}, Req, State) ->
+ erlang:start_timer(1000, self(), <<"websocket_handle">>),
+ {reply, Msg, Req, State};
+websocket_handle({websocket, Data}, Req, State) ->
+ {reply, Data, Req, State}.
+
+websocket_terminate(_Reason, _Req, _State) ->
+ ok.