mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
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.
This commit is contained in:
parent
288deb5b88
commit
4c34774b7e
5 changed files with 105 additions and 8 deletions
22
test/ws_SUITE_data/ws_max_frame_size.erl
Normal file
22
test/ws_SUITE_data/ws_max_frame_size.erl
Normal file
|
@ -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}.
|
Loading…
Add table
Add a link
Reference in a new issue