From d9a970be90d0105af215531d74809878f9c21338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 24 Sep 2019 19:18:35 +0200 Subject: Add auto-ping to Websocket and a silence_pings option The auto-ping will at regular interval send a ping frame. The silence_pings option defaults to true. It can be set to false when the user needs to receive ping/pong frames. --- src/gun_http.erl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/gun_http.erl') diff --git a/src/gun_http.erl b/src/gun_http.erl index 87b50c8..f27563e 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -25,7 +25,7 @@ -export([update_flow/4]). -export([closing/4]). -export([close/4]). --export([keepalive/1]). +-export([keepalive/3]). -export([headers/11]). -export([request/12]). -export([data/7]). @@ -473,14 +473,14 @@ close_streams([#stream{ref=StreamRef, reply_to=ReplyTo}|Tail], Reason) -> close_streams(Tail, Reason). %% We don't send a keep-alive when a CONNECT request was initiated. -keepalive(State=#http_state{streams=[#stream{ref={connect, _, _}}]}) -> - State; +keepalive(State=#http_state{streams=[#stream{ref={connect, _, _}}]}, _, EvHandlerState) -> + {State, EvHandlerState}; %% We can only keep-alive by sending an empty line in-between streams. -keepalive(State=#http_state{socket=Socket, transport=Transport, out=head}) -> +keepalive(State=#http_state{socket=Socket, transport=Transport, out=head}, _, EvHandlerState) -> Transport:send(Socket, <<"\r\n">>), - State; -keepalive(State) -> - State. + {State, EvHandlerState}; +keepalive(State, _, EvHandlerState) -> + {State, EvHandlerState}. headers(State=#http_state{opts=Opts, out=head}, StreamRef, ReplyTo, Method, Host, Port, Path, Headers, -- cgit v1.2.3