From 145b2c56ffe6edcc5b73c6698097b16a3fb04fcc Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 20 Nov 2023 12:16:12 -0600 Subject: [PATCH] config: add new config values for read, write and idle timeout --- aperture.go | 10 +++++++--- config.go | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/aperture.go b/aperture.go index f3ed9e1..5fbb4dd 100644 --- a/aperture.go +++ b/aperture.go @@ -379,11 +379,15 @@ func (a *Aperture) Start(errChan chan error) error { a.httpsServer = &http.Server{ Addr: a.cfg.ListenAddr, Handler: handler, - IdleTimeout: time.Minute * 2, - ReadTimeout: time.Second * 15, - WriteTimeout: time.Second * 30, + IdleTimeout: a.cfg.IdleTimeout, + ReadTimeout: a.cfg.ReadTimeout, + WriteTimeout: a.cfg.WriteTimeout, } + log.Infof("Creating server with idle_timeout=%v, read_timeout=%v "+ + "and write_timeout=%v", a.cfg.IdleTimeout, a.cfg.ReadTimeout, + a.cfg.WriteTimeout) + // Create TLS configuration by either creating new self-signed certs or // trying to obtain one through Let's Encrypt. var serveFn func() error diff --git a/config.go b/config.go index 66e55de..7925233 100644 --- a/config.go +++ b/config.go @@ -30,6 +30,12 @@ var ( ) ) +const ( + defaultIdleTimeout = time.Minute * 2 + defaultReadTimeout = time.Second * 15 + defaultWriteTimeout = time.Second * 30 +) + type EtcdConfig struct { Host string `long:"host" description:"host:port of an active etcd instance"` User string `long:"user" description:"user authorized to access the etcd host"` @@ -202,6 +208,17 @@ type Config struct { // Profile is the port on which the pprof profile will be served. Profile uint16 `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"` + + // IdleTimeout is the maximum amount of time a connection may be idle. + IdleTimeout time.Duration `long:"idletimeout" description:"The maximum amount of time a connection may be idle before being closed."` + + // ReadTimeout is the maximum amount of time to wait for a request to + // be fully read. + ReadTimeout time.Duration `long:"readtimeout" description:"The maximum amount of time to wait for a request to be fully read."` + + // WriteTimeout is the maximum amount of time to wait for a response to + // be fully written. + WriteTimeout time.Duration `long:"writetimeout" description:"The maximum amount of time to wait for a response to be fully written."` } func (c *Config) validate() error { @@ -237,5 +254,8 @@ func NewConfig() *Config { Tor: &TorConfig{}, HashMail: &HashMailConfig{}, Prometheus: &PrometheusConfig{}, + IdleTimeout: defaultIdleTimeout, + ReadTimeout: defaultReadTimeout, + WriteTimeout: defaultWriteTimeout, } }