From 067958abd200c1c3fbc1956d4c6c30bc5efd344c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Sun, 2 Dec 2012 21:37:24 +0100 Subject: Add more frame types available in websocket replies We can now reply empty close, ping and pong frames, or close frames with a payload. This means that we can send a frame and then close the connection in a single operation. If a close packet is sent, the connection is closed immediately, even if there was frames that remained to be sent. Cowboy will silently drop any extra frames in the list given as a reply. --- test/ws_send_many_handler.erl | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'test/ws_send_many_handler.erl') diff --git a/test/ws_send_many_handler.erl b/test/ws_send_many_handler.erl index ee386ba..bd67814 100644 --- a/test/ws_send_many_handler.erl +++ b/test/ws_send_many_handler.erl @@ -12,20 +12,16 @@ init(_Any, _Req, _Opts) -> {upgrade, protocol, cowboy_websocket}. -websocket_init(_TransportName, Req, _Opts) -> +websocket_init(_TransportName, Req, Sequence) -> Req2 = cowboy_req:compact(Req), erlang:send_after(10, self(), send_many), - {ok, Req2, undefined}. + {ok, Req2, Sequence}. websocket_handle(_Frame, Req, State) -> {ok, Req, State}. -websocket_info(send_many, Req, State) -> - {reply, [ - {text, <<"one">>}, - {text, <<"two">>}, - {text, <<"seven!">>} - ], Req, State}. +websocket_info(send_many, Req, State = [{sequence, Sequence}]) -> + {reply, Sequence, Req, State}. websocket_terminate(_Reason, _Req, _State) -> ok. -- cgit v1.2.3