0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Add the set_options Websocket command

It allows overriding the idle_timeout option only for now.
This commit is contained in:
Loïc Hoguin 2018-11-16 13:48:15 +01:00
parent 75045637fc
commit f5015cb14b
No known key found for this signature in database
GPG key ID: 8A9DF795F6FED764
3 changed files with 59 additions and 1 deletions

View file

@ -0,0 +1,20 @@
%% This module sets options based on the frame received.
-module(ws_set_options_commands_h).
-behavior(cowboy_websocket).
-export([init/2]).
-export([websocket_handle/2]).
-export([websocket_info/2]).
init(Req, RunOrHibernate) ->
{cowboy_websocket, Req, RunOrHibernate,
#{idle_timeout => infinity}}.
websocket_handle(Frame={text, <<"idle_timeout_short">>}, State=run) ->
{[{set_options, #{idle_timeout => 500}}, Frame], State};
websocket_handle(Frame={text, <<"idle_timeout_short">>}, State=hibernate) ->
{[{set_options, #{idle_timeout => 500}}, Frame], State, hibernate}.
websocket_info(_Info, State) ->
{[], State}.