Set server timeouts

Set server timeouts to avoid leaked descriptors on slow or
disappearing clients or slow http attacks.

Fixes #51
This commit is contained in:
Peter Etelej 2018-03-06 19:10:49 +03:00
parent 9d3c8eedf9
commit 12c118f4bc
No known key found for this signature in database
GPG key ID: C19A90B496F44BEB

View file

@ -74,7 +74,13 @@ var (
port, _ := cmd.Flags().GetInt("port")
url := fmt.Sprintf(":%d", port)
logrus.Infoln("Serve shiori in", url)
logrus.Fatalln(http.ListenAndServe(url, router))
svr := &http.Server{
Addr: url,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 20 * time.Second,
}
logrus.Fatalln(svr.ListenAndServe())
},
}
)