Skip to content

Commit

Permalink
config: add new config values for read, write and idle timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Nov 20, 2023
1 parent 9ea2efc commit 145b2c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 7 additions & 3 deletions aperture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -237,5 +254,8 @@ func NewConfig() *Config {
Tor: &TorConfig{},
HashMail: &HashMailConfig{},
Prometheus: &PrometheusConfig{},
IdleTimeout: defaultIdleTimeout,
ReadTimeout: defaultReadTimeout,
WriteTimeout: defaultWriteTimeout,
}
}

0 comments on commit 145b2c5

Please sign in to comment.