Explicitly define timeouts for http and https

This commit is contained in:
Jan Dittberner 2020-04-26 13:18:58 +02:00
parent bf67dfbc10
commit 594df29dc1

View file

@ -848,6 +848,10 @@ func main() {
server := &http.Server{ server := &http.Server{
Addr: config.HttpsAddress, Addr: config.HttpsAddress,
TLSConfig: tlsConfig, TLSConfig: tlsConfig,
IdleTimeout: time.Second * 120,
ReadHeaderTimeout: time.Second * 10,
ReadTimeout: time.Second * 20,
WriteTimeout: time.Second * 60,
} }
server.Handler = csrf.Protect(csrfKey)(http.DefaultServeMux) server.Handler = csrf.Protect(csrfKey)(http.DefaultServeMux)
@ -856,7 +860,15 @@ func main() {
errs := make(chan error, 1) errs := make(chan error, 1)
go func() { go func() {
if err := http.ListenAndServe(config.HttpsAddress, http.RedirectHandler(config.BaseURL, http.StatusMovedPermanently)); err != nil { httpRedirector := &http.Server{
Addr: config.HttpAddress,
Handler: http.RedirectHandler(config.BaseURL, http.StatusMovedPermanently),
IdleTimeout: time.Second * 5,
ReadHeaderTimeout: time.Second * 10,
ReadTimeout: time.Second * 10,
WriteTimeout: time.Second * 60,
}
if err := httpRedirector.ListenAndServe(); err != nil {
errs <- err errs <- err
} }
close(errs) close(errs)