Disable keepalive connections and set idle timeout to 10 seconds, explicitly
This commit is contained in:
@@ -14,6 +14,9 @@ const (
|
|||||||
// maxHeaderBytes is the maximum size of request headers (1KB).
|
// maxHeaderBytes is the maximum size of request headers (1KB).
|
||||||
maxHeaderBytes = 1024
|
maxHeaderBytes = 1024
|
||||||
|
|
||||||
|
// idleTimeout is the maximum time to wait for the next request on keep-alive connections.
|
||||||
|
idleTimeout = 10 * time.Second
|
||||||
|
|
||||||
// portMin is the minimum valid port number.
|
// portMin is the minimum valid port number.
|
||||||
portMin = 1
|
portMin = 1
|
||||||
|
|
||||||
|
|||||||
@@ -178,31 +178,39 @@ func NewServer(configPath string) (*ServerWrapper, error) {
|
|||||||
// HTTP mode if nohttps is enabled in config.
|
// HTTP mode if nohttps is enabled in config.
|
||||||
// HTTPS mode if nohttps is disabled in config.
|
// HTTPS mode if nohttps is disabled in config.
|
||||||
if C.NoHTTPS {
|
if C.NoHTTPS {
|
||||||
return &ServerWrapper{
|
srv := &ServerWrapper{
|
||||||
Server: &http.Server{
|
Server: &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
||||||
Handler: withServerHeader(mux),
|
Handler: withServerHeader(mux),
|
||||||
ReadHeaderTimeout: readHeaderTimeout,
|
ReadHeaderTimeout: readHeaderTimeout,
|
||||||
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
||||||
|
IdleTimeout: idleTimeout,
|
||||||
MaxHeaderBytes: maxHeaderBytes,
|
MaxHeaderBytes: maxHeaderBytes,
|
||||||
ErrorLog: log.DebugLogger(),
|
ErrorLog: log.DebugLogger(),
|
||||||
},
|
},
|
||||||
}, nil
|
}
|
||||||
|
srv.SetKeepAlivesEnabled(false)
|
||||||
|
|
||||||
|
return srv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ServerWrapper{
|
srv := &ServerWrapper{
|
||||||
Server: &http.Server{
|
Server: &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
Addr: fmt.Sprintf("%s:%d", C.Address, C.Port),
|
||||||
Handler: withServerHeader(mux),
|
Handler: withServerHeader(mux),
|
||||||
ReadHeaderTimeout: readHeaderTimeout,
|
ReadHeaderTimeout: readHeaderTimeout,
|
||||||
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
WriteTimeout: time.Duration(C.BackupTimeout) * time.Minute,
|
||||||
|
IdleTimeout: idleTimeout,
|
||||||
MaxHeaderBytes: maxHeaderBytes,
|
MaxHeaderBytes: maxHeaderBytes,
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
MinVersion: tls.VersionTLS13,
|
MinVersion: tls.VersionTLS13,
|
||||||
},
|
},
|
||||||
ErrorLog: log.DebugLogger(),
|
ErrorLog: log.DebugLogger(),
|
||||||
},
|
},
|
||||||
}, nil
|
}
|
||||||
|
srv.SetKeepAlivesEnabled(false)
|
||||||
|
|
||||||
|
return srv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeWithContext checks if context is canceled before executing fn.
|
// writeWithContext checks if context is canceled before executing fn.
|
||||||
|
|||||||
Reference in New Issue
Block a user