reverse_proxy: use the new KeepAliveConfig to set probe interval (#7157)

Co-authored-by: Matt Holt <mholt@users.noreply.github.com>
This commit is contained in:
WeidiDeng 2025-08-22 04:36:54 +08:00 committed by GitHub
parent f11c780fdc
commit 1c596e3c5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -428,7 +428,19 @@ func (h *HTTPTransport) NewTransport(caddyCtx caddy.Context) (*http.Transport, e
}
if h.KeepAlive != nil {
// according to https://pkg.go.dev/net#Dialer.KeepAliveConfig,
// KeepAlive is ignored if KeepAliveConfig.Enable is true.
// If configured to 0, a system-dependent default is used.
// To disable tcp keepalive, choose a negative value,
// so KeepAliveConfig.Enable is false and KeepAlive is negative.
// This is different from http keepalive where a tcp connection
// can transfer multiple http requests/responses.
dialer.KeepAlive = time.Duration(h.KeepAlive.ProbeInterval)
dialer.KeepAliveConfig = net.KeepAliveConfig{
Enable: h.KeepAlive.ProbeInterval > 0,
Interval: time.Duration(h.KeepAlive.ProbeInterval),
}
if h.KeepAlive.Enabled != nil {
rt.DisableKeepAlives = !*h.KeepAlive.Enabled
}