From 8c5019d3bcdb5ade118217d081e9d071b4ff9232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 20 Sep 2019 12:40:05 +0200 Subject: Improve retrieval of keepalive option --- src/gun.erl | 8 ++------ src/gun_http.erl | 2 ++ src/gun_http2.erl | 2 ++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gun.erl b/src/gun.erl index 5a7750b..5bf37fb 100644 --- a/src/gun.erl +++ b/src/gun.erl @@ -1389,12 +1389,8 @@ status(State, NewStatus) -> State#state{status=NewStatus}. keepalive_timeout(State=#state{opts=Opts, protocol=Protocol}) -> - {ProtoOptsKey, Default} = case Protocol of - gun_http -> {http_opts, infinity}; - gun_http2 -> {http2_opts, 5000} - end, - ProtoOpts = maps:get(ProtoOptsKey, Opts, #{}), - Keepalive = maps:get(keepalive, ProtoOpts, Default), + ProtoOpts = maps:get(Protocols:opts_name(), Opts, #{}), + Keepalive = maps:get(keepalive, ProtoOpts, Protocol:default_keepalive()), KeepaliveRef = case Keepalive of infinity -> undefined; %% @todo Maybe change that to a start_timer. diff --git a/src/gun_http.erl b/src/gun_http.erl index ba5c01d..2c26d01 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -18,6 +18,7 @@ -export([name/0]). -export([opts_name/0]). -export([has_keepalive/0]). +-export([default_keepalive/0]). -export([init/4]). -export([switch_transport/3]). -export([handle/4]). @@ -100,6 +101,7 @@ do_check_options([Opt|_]) -> name() -> http. opts_name() -> http_opts. has_keepalive() -> true. +default_keepalive() -> infinity. init(Owner, Socket, Transport, Opts) -> %% @todo If we keep the opts we don't need to add these to the state. diff --git a/src/gun_http2.erl b/src/gun_http2.erl index efa7afa..66e7732 100644 --- a/src/gun_http2.erl +++ b/src/gun_http2.erl @@ -18,6 +18,7 @@ -export([name/0]). -export([opts_name/0]). -export([has_keepalive/0]). +-export([default_keepalive/0]). -export([init/4]). -export([switch_transport/3]). -export([handle/4]). @@ -101,6 +102,7 @@ do_check_options([Opt|_]) -> name() -> http2. opts_name() -> http2_opts. has_keepalive() -> true. +default_keepalive() -> 5000. init(Owner, Socket, Transport, Opts0) -> %% We have different defaults than the protocol in order -- cgit v1.2.3