diff options
author | Kassio Borges <kassioborgesm@gmail.com> | 2023-05-17 18:02:06 +0300 |
---|---|---|
committer | Kassio Borges <kassioborgesm@gmail.com> | 2023-05-17 18:02:06 +0300 |
commit | 89c333a866ceef7d6d970999a13778804d7a45cc (patch) | |
tree | 16d28a55611ed608b9a422f1d0cd19cb2b26d55a /server.go | |
parent | f86f076800e10bac97c9d7cde04ba38300a2aa63 (diff) |
Ensure to use configured timeouts in http.Server
Diffstat (limited to 'server.go')
-rw-r--r-- | server.go | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -22,6 +22,15 @@ type listenerConfig struct { limiter *netutil.Limiter } +func newHTTPServer(a *theApp) *http.Server { + return &http.Server{ + ReadTimeout: a.config.Server.ReadTimeout, + ReadHeaderTimeout: a.config.Server.ReadHeaderTimeout, + WriteTimeout: a.config.Server.WriteTimeout, + ErrorLog: stdlog.New(logrus.StandardLogger().Writer(), "", 0), + } +} + func (a *theApp) listenAndServe(server *http.Server, addr string, h http.Handler, opts ...option) error { config := &listenerConfig{} @@ -33,17 +42,12 @@ func (a *theApp) listenAndServe(server *http.Server, addr string, h http.Handler server.Handler = h server.TLSConfig = config.tlsConfig - server.ErrorLog = stdlog.New(logrus.StandardLogger().Writer(), "", 0) // ensure http2 is enabled even if TLSConfig is not null // See https://github.com/golang/go/blob/97cee43c93cfccded197cd281f0a5885cdb605b4/src/net/http/server.go#L2947-L2954 if server.TLSConfig != nil { server.TLSConfig.NextProtos = append(server.TLSConfig.NextProtos, "h2") } - server.ReadTimeout = a.config.Server.ReadTimeout - server.ReadHeaderTimeout = a.config.Server.ReadHeaderTimeout - server.WriteTimeout = a.config.Server.WriteTimeout - lc := net.ListenConfig{ KeepAlive: a.config.Server.ListenKeepAlive, } |