diff options
author | Kirill Kinduk <[email protected]> | 2017-08-25 12:08:26 +0300 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-03-28 16:58:02 +0200 |
commit | 4c34774b7eb787e37892399f2daddba68ec277e3 (patch) | |
tree | 8640e0950bb363acde6f87f1f7a2977d3185c852 /test/ws_SUITE_data | |
parent | 288deb5b88dd8e0aae57c9858d16c19ca9f186f9 (diff) | |
download | cowboy-4c34774b7eb787e37892399f2daddba68ec277e3.tar.gz cowboy-4c34774b7eb787e37892399f2daddba68ec277e3.tar.bz2 cowboy-4c34774b7eb787e37892399f2daddba68ec277e3.zip |
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.
Diffstat (limited to 'test/ws_SUITE_data')
-rw-r--r-- | test/ws_SUITE_data/ws_max_frame_size.erl | 22 |
1 files changed, 22 insertions, 0 deletions
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}. |