Improve HTTP timeout config

This commit is contained in:
2025-01-05 15:35:27 -05:00
parent 4a99f06987
commit c6514e0590
5 changed files with 80 additions and 28 deletions

View File

@ -17,11 +17,11 @@ import (
)
var (
httpMeter metric.Meter
httpTracer trace.Tracer
readTimeout = 10 * time.Second
writeTimeout = 10 * time.Second
idleTimeout = 15 * time.Second
httpMeter metric.Meter
httpTracer trace.Tracer
defReadTimeout = 10 * time.Second
defWriteTimeout = 10 * time.Second
defIdleTimeout = 15 * time.Second
)
type HTTPFunc struct {
@ -72,6 +72,23 @@ func prepHTTPServer(ctx context.Context, handleFuncs []HTTPFunc, hcFuncs ...Heal
}
}))
// Set timeouts from defaults, override
// with config timeouts if set
readTimeout := defReadTimeout
writeTimeout := defWriteTimeout
idleTimeout := defIdleTimeout
rT, wT, iT := cfg.HTTP.Timeouts()
if rT != nil {
readTimeout = *rT
}
if wT != nil {
writeTimeout = *wT
}
if iT != nil {
idleTimeout = *iT
}
return &http.Server{
Addr: cfg.HTTP.Listen,
ReadTimeout: readTimeout,