From 4c34774b7eb787e37892399f2daddba68ec277e3 Mon Sep 17 00:00:00 2001 From: Kirill Kinduk Date: Fri, 25 Aug 2017 12:08:26 +0300 Subject: Add max_frame_size option for websocket handlers Option allows to limit a frame by size before decoding its payload. LH: I have added a test for when the limit is reached on a nofin fragmented frame (the last commit addressed that case but it had no test). I have fixed formatting and other, and changed the default value to infinity since it might otherwise be incompatible with existing code. I also added documentation and a bunch of other minor changes. --- test/ws_SUITE_data/ws_max_frame_size.erl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/ws_SUITE_data/ws_max_frame_size.erl (limited to 'test/ws_SUITE_data') diff --git a/test/ws_SUITE_data/ws_max_frame_size.erl b/test/ws_SUITE_data/ws_max_frame_size.erl new file mode 100644 index 0000000..2d34218 --- /dev/null +++ b/test/ws_SUITE_data/ws_max_frame_size.erl @@ -0,0 +1,22 @@ +-module(ws_max_frame_size). + +-export([init/2]). +-export([websocket_init/1]). +-export([websocket_handle/2]). +-export([websocket_info/2]). + +init(Req, State) -> + {cowboy_websocket, Req, State, #{max_frame_size => 8}}. + +websocket_init(State) -> + {ok, State}. + +websocket_handle({text, Data}, State) -> + {reply, {text, Data}, State}; +websocket_handle({binary, Data}, State) -> + {reply, {binary, Data}, State}; +websocket_handle(_Frame, State) -> + {ok, State}. + +websocket_info(_Info, State) -> + {ok, State}. -- cgit v1.2.3