From f5015cb14bbadef95285460f3d842fbbb05c33c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 16 Nov 2018 13:48:15 +0100 Subject: Add the set_options Websocket command It allows overriding the idle_timeout option only for now. --- src/cowboy_websocket.erl | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index b460745..a94a5ce 100644 --- a/src/cowboy_websocket.erl +++ b/src/cowboy_websocket.erl @@ -34,6 +34,7 @@ -type commands() :: [cow_ws:frame() | {active, boolean()} | {deflate, boolean()} + | {set_options, map()} ]. -export_type([commands/0]). @@ -527,6 +528,14 @@ commands([{active, Active}|Tail], State, Data) when is_boolean(Active) -> 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} -> + loop_timeout(State0#state{opts=Opts#{idle_timeout => IdleTimeout}}); + _ -> + State0 + end, + commands(Tail, State, Data); commands([Frame|Tail], State, Data0) -> Data = [frame(Frame, State)|Data0], case is_close_frame(Frame) of -- cgit v1.2.3