Improve HTTP timeout config
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user