diff options
author | Loïc Hoguin <[email protected]> | 2025-01-16 14:40:37 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2025-01-16 14:47:20 +0100 |
commit | 81de580aeec405481cacb618a131fa895605004b (patch) | |
tree | 52f789b64dea14a10fa0e4b1cdedc989fa443f56 /src | |
parent | 818b448ae9eab17aadc8ea2bacaa82948a2e9b56 (diff) | |
download | cowboy-81de580aeec405481cacb618a131fa895605004b.tar.gz cowboy-81de580aeec405481cacb618a131fa895605004b.tar.bz2 cowboy-81de580aeec405481cacb618a131fa895605004b.zip |
Websocket: Allow setting the max_frame_size option dynamically
This can be used to limit the maximum frame size before
some authentication or other validation is completed.
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_websocket.erl | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index 577de47..12c99ba 100644 --- a/src/cowboy_websocket.erl +++ b/src/cowboy_websocket.erl @@ -615,14 +615,16 @@ commands([{active, Active}|Tail], State0=#state{active=Active0}, Data) when is_b commands(Tail, State#state{active=Active}, Data); commands([{deflate, Deflate}|Tail], State, Data) when is_boolean(Deflate) -> commands(Tail, State#state{deflate=Deflate}, Data); -commands([{set_options, SetOpts}|Tail], State0=#state{opts=Opts}, Data) -> - State = case SetOpts of - #{idle_timeout := IdleTimeout} -> +commands([{set_options, SetOpts}|Tail], State0, Data) -> + State = maps:fold(fun + (idle_timeout, IdleTimeout, StateF=#state{opts=Opts}) -> %% We reset the number of ticks when changing the idle_timeout option. - set_idle_timeout(State0#state{opts=Opts#{idle_timeout => IdleTimeout}}, 0); - _ -> - State0 - end, + set_idle_timeout(StateF#state{opts=Opts#{idle_timeout => IdleTimeout}}, 0); + (max_frame_size, MaxFrameSize, StateF=#state{opts=Opts}) -> + StateF#state{opts=Opts#{max_frame_size => MaxFrameSize}}; + (_, _, StateF) -> + StateF + end, State0, SetOpts), commands(Tail, State, Data); commands([{shutdown_reason, ShutdownReason}|Tail], State, Data) -> commands(Tail, State#state{shutdown_reason=ShutdownReason}, Data); |