aboutsummaryrefslogtreecommitdiffstats
path: root/test/handlers/ws_ping_h.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2024-01-16 12:20:38 +0100
committerLoïc Hoguin <[email protected]>2024-01-16 12:20:38 +0100
commit08a8d7b9e981002545bf77af367c734d9ea162ab (patch)
tree7f1d03b94f57a787ffaf9f7bfbb87f2bdd7a4216 /test/handlers/ws_ping_h.erl
parent920adb9b8258bf60f167f7ef86d33e66e467fcd7 (diff)
downloadcowboy-08a8d7b9e981002545bf77af367c734d9ea162ab.tar.gz
cowboy-08a8d7b9e981002545bf77af367c734d9ea162ab.tar.bz2
cowboy-08a8d7b9e981002545bf77af367c734d9ea162ab.zip
Confirm Websocket pong frames are received by handlers
Diffstat (limited to 'test/handlers/ws_ping_h.erl')
-rw-r--r--test/handlers/ws_ping_h.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/handlers/ws_ping_h.erl b/test/handlers/ws_ping_h.erl
new file mode 100644
index 0000000..a5848fe
--- /dev/null
+++ b/test/handlers/ws_ping_h.erl
@@ -0,0 +1,23 @@
+%% This module sends an empty ping to the client and
+%% waits for a pong before sending a text frame. It
+%% is used to confirm server-initiated pings work.
+
+-module(ws_ping_h).
+-behavior(cowboy_websocket).
+
+-export([init/2]).
+-export([websocket_init/1]).
+-export([websocket_handle/2]).
+-export([websocket_info/2]).
+
+init(Req, _) ->
+ {cowboy_websocket, Req, undefined}.
+
+websocket_init(State) ->
+ {[{ping, <<>>}], State}.
+
+websocket_handle(pong, State) ->
+ {[{text, <<"OK!!">>}], State}.
+
+websocket_info(_, State) ->
+ {[], State}.