rpc: add http.TimeoutHandler for http server

This commit is contained in:
Daniel Liu 2024-03-03 22:05:24 +08:00
parent 38a192e672
commit 7bd39e6bf9

View file

@ -237,11 +237,12 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server, writeTimeout tim
// Wrap the CORS-handler within a host-handler
handler := newCorsHandler(srv, cors)
handler = newVHostHandler(vhosts, handler)
handler = http.TimeoutHandler(handler, writeTimeout, `{"error":"http server timeout"}`)
log.Info("NewHTTPServer", "writeTimeout", writeTimeout)
return &http.Server{
Handler: handler,
ReadTimeout: 5 * time.Second,
WriteTimeout: writeTimeout,
WriteTimeout: writeTimeout + time.Second,
IdleTimeout: 120 * time.Second,
}
}