Skip to content

Commit 145b2c5

Browse files
committed
config: add new config values for read, write and idle timeout
1 parent 9ea2efc commit 145b2c5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

aperture.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,15 @@ func (a *Aperture) Start(errChan chan error) error {
379379
a.httpsServer = &http.Server{
380380
Addr: a.cfg.ListenAddr,
381381
Handler: handler,
382-
IdleTimeout: time.Minute * 2,
383-
ReadTimeout: time.Second * 15,
384-
WriteTimeout: time.Second * 30,
382+
IdleTimeout: a.cfg.IdleTimeout,
383+
ReadTimeout: a.cfg.ReadTimeout,
384+
WriteTimeout: a.cfg.WriteTimeout,
385385
}
386386

387+
log.Infof("Creating server with idle_timeout=%v, read_timeout=%v "+
388+
"and write_timeout=%v", a.cfg.IdleTimeout, a.cfg.ReadTimeout,
389+
a.cfg.WriteTimeout)
390+
387391
// Create TLS configuration by either creating new self-signed certs or
388392
// trying to obtain one through Let's Encrypt.
389393
var serveFn func() error

config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ var (
3030
)
3131
)
3232

33+
const (
34+
defaultIdleTimeout = time.Minute * 2
35+
defaultReadTimeout = time.Second * 15
36+
defaultWriteTimeout = time.Second * 30
37+
)
38+
3339
type EtcdConfig struct {
3440
Host string `long:"host" description:"host:port of an active etcd instance"`
3541
User string `long:"user" description:"user authorized to access the etcd host"`
@@ -202,6 +208,17 @@ type Config struct {
202208

203209
// Profile is the port on which the pprof profile will be served.
204210
Profile uint16 `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"`
211+
212+
// IdleTimeout is the maximum amount of time a connection may be idle.
213+
IdleTimeout time.Duration `long:"idletimeout" description:"The maximum amount of time a connection may be idle before being closed."`
214+
215+
// ReadTimeout is the maximum amount of time to wait for a request to
216+
// be fully read.
217+
ReadTimeout time.Duration `long:"readtimeout" description:"The maximum amount of time to wait for a request to be fully read."`
218+
219+
// WriteTimeout is the maximum amount of time to wait for a response to
220+
// be fully written.
221+
WriteTimeout time.Duration `long:"writetimeout" description:"The maximum amount of time to wait for a response to be fully written."`
205222
}
206223

207224
func (c *Config) validate() error {
@@ -237,5 +254,8 @@ func NewConfig() *Config {
237254
Tor: &TorConfig{},
238255
HashMail: &HashMailConfig{},
239256
Prometheus: &PrometheusConfig{},
257+
IdleTimeout: defaultIdleTimeout,
258+
ReadTimeout: defaultReadTimeout,
259+
WriteTimeout: defaultWriteTimeout,
240260
}
241261
}

0 commit comments

Comments
 (0)