mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-17 13:29:35 +00:00
caddyhttp: document that negative idle timeouts disable them (#8146)
read_idle_timeout and write_idle_timeout default to 1 minute when zero,
and the wrappers are only installed for positive values, so a negative
value already disables them. Document it and cover it with tests, since
it is the only way to opt out, for instance behind a reverse proxy that
already protects from slow clients.
(cherry picked from commit c65c248336)
This commit is contained in:
parent
53a2833af5
commit
96199dc4dc
3 changed files with 66 additions and 2 deletions
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
servers {
|
||||
timeouts {
|
||||
read_body_idle -1s
|
||||
write_idle -1s
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:80 {
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":80"
|
||||
],
|
||||
"read_idle_timeout": -1000000000,
|
||||
"write_idle_timeout": -1000000000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,7 +74,8 @@ type Server struct {
|
|||
// it mitigates slowloris-style attacks without penalizing large
|
||||
// uploads from legitimately slow clients. Combine with ReadTimeout
|
||||
// for a hard ceiling on top.
|
||||
// Default is 1 minute.
|
||||
// Default is 1 minute. A negative value disables it, for instance
|
||||
// behind a proxy that already buffers request bodies.
|
||||
ReadIdleTimeout caddy.Duration `json:"read_idle_timeout,omitempty"`
|
||||
|
||||
// ReadMinRate, if set, requires the client to sustain at least this
|
||||
|
|
@ -97,7 +98,8 @@ type Server struct {
|
|||
// response, or pauses between writes (e.g. SSE), is unaffected as
|
||||
// long as each individual write keeps making progress. Combine
|
||||
// with WriteTimeout for a hard ceiling on top.
|
||||
// Default is 1 minute.
|
||||
// Default is 1 minute. A negative value disables it, for instance
|
||||
// behind a proxy that already times out slow clients.
|
||||
WriteIdleTimeout caddy.Duration `json:"write_idle_timeout,omitempty"`
|
||||
|
||||
// WriteMinRate is like ReadMinRate, but for writes to the client.
|
||||
|
|
|
|||
|
|
@ -1534,3 +1534,38 @@ func TestServer_ServeHTTP_DelayedHandlerErrorWritesErrorStatus(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_ServeHTTP_IdleTimeouts(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
timeout caddy.Duration
|
||||
applied bool
|
||||
}{
|
||||
{name: "positive", timeout: caddy.Duration(time.Minute), applied: true},
|
||||
{name: "negative disables", timeout: -1},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var reader *IdleTimeoutReader
|
||||
var writer *IdleTimeoutWriter
|
||||
s := &Server{
|
||||
ReadIdleTimeout: tc.timeout,
|
||||
WriteIdleTimeout: tc.timeout,
|
||||
logger: zap.NewNop(),
|
||||
errorLogger: zap.NewNop(),
|
||||
primaryHandlerChain: HandlerFunc(func(_ http.ResponseWriter, r *http.Request) error {
|
||||
reader, writer = IdleTimeoutsFromContext(r.Context())
|
||||
return nil
|
||||
}),
|
||||
}
|
||||
ts := httptest.NewServer(http.HandlerFunc(s.ServeHTTP))
|
||||
t.Cleanup(ts.Close)
|
||||
|
||||
resp, err := ts.Client().Post(ts.URL, "text/plain", strings.NewReader("x"))
|
||||
require.NoError(t, err)
|
||||
resp.Body.Close()
|
||||
|
||||
assert.Equal(t, tc.applied, reader != nil)
|
||||
assert.Equal(t, tc.applied, writer != nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue