Skip to content

Commit 197c564

Browse files
committed
caddyhttp: Set default ReadHeaderTimeout (1 min)
Ref. #6663
1 parent b3ce260 commit 197c564

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

modules/caddyhttp/app.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ func (app *App) Provision(ctx caddy.Context) error {
401401
if srv.IdleTimeout == 0 {
402402
srv.IdleTimeout = defaultIdleTimeout
403403
}
404+
if srv.ReadHeaderTimeout == 0 {
405+
srv.ReadHeaderTimeout = defaultReadHeaderTimeout // see #6663
406+
}
404407
}
405408
ctx.Context = oldContext
406409
return nil
@@ -770,11 +773,20 @@ func (app *App) httpsPort() int {
770773
return app.HTTPSPort
771774
}
772775

773-
// defaultIdleTimeout is the default HTTP server timeout
774-
// for closing idle connections; useful to avoid resource
775-
// exhaustion behind hungry CDNs, for example (we've had
776-
// several complaints without this).
777-
const defaultIdleTimeout = caddy.Duration(5 * time.Minute)
776+
const (
777+
// defaultIdleTimeout is the default HTTP server timeout
778+
// for closing idle connections; useful to avoid resource
779+
// exhaustion behind hungry CDNs, for example (we've had
780+
// several complaints without this).
781+
defaultIdleTimeout = caddy.Duration(5 * time.Minute)
782+
783+
// defaultReadHeaderTimeout is the default timeout for
784+
// reading HTTP headers from clients. Headers are generally
785+
// small, often less than 1 KB, so it shouldn't take a
786+
// long time even on legitimately slow connections or
787+
// busy servers to read it.
788+
defaultReadHeaderTimeout = caddy.Duration(time.Minute)
789+
)
778790

779791
// Interface guards
780792
var (

modules/caddyhttp/server.go

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type Server struct {
6161
ReadTimeout caddy.Duration `json:"read_timeout,omitempty"`
6262

6363
// ReadHeaderTimeout is like ReadTimeout but for request headers.
64+
// Default is 1 minute.
6465
ReadHeaderTimeout caddy.Duration `json:"read_header_timeout,omitempty"`
6566

6667
// WriteTimeout is how long to allow a write to a client. Note

0 commit comments

Comments
 (0)