0
Fork 0
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:
Kirill Kinduk 2017-08-25 12:08:26 +03:00 committed by Loïc Hoguin
parent 288deb5b88
commit 4c34774b7e
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
5 changed files with 105 additions and 8 deletions

View 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}.