Implement route-specific timeouts

This commit is contained in:
Tobie Morgan Hitchcock 2019-11-21 02:07:13 +00:00
parent 4482e62d2d
commit a840f660dd
2 changed files with 12 additions and 2 deletions

View file

@ -77,6 +77,10 @@ func routes(s *fibre.Fibre) {
s.Rpc("/rpc", &rpc{}) s.Rpc("/rpc", &rpc{})
s.Use(mw.Quit(&mw.QuitOpts{
Timeout: 15 * time.Second,
}).PathIs("/rpc"))
// -------------------------------------------------- // --------------------------------------------------
// Endpoints for syncing data // Endpoints for syncing data
// -------------------------------------------------- // --------------------------------------------------
@ -167,6 +171,10 @@ func routes(s *fibre.Fibre) {
return c.Send(200, res) return c.Send(200, res)
}) })
s.Use(mw.Quit(&mw.QuitOpts{
Timeout: 15 * time.Second,
}).PathIs("/sql"))
s.Use(mw.Type(&mw.TypeOpts{ s.Use(mw.Type(&mw.TypeOpts{
AllowedContent: map[string]bool{ AllowedContent: map[string]bool{
"text/plain": true, "text/plain": true,
@ -354,6 +362,10 @@ func routes(s *fibre.Fibre) {
}) })
s.Use(mw.Quit(&mw.QuitOpts{
Timeout: 5 * time.Second,
}).PathBegsWith("/key/"))
s.Use(mw.Type(&mw.TypeOpts{ s.Use(mw.Type(&mw.TypeOpts{
AllowedContent: map[string]bool{ AllowedContent: map[string]bool{
"application/json": true, "application/json": true,

View file

@ -32,8 +32,6 @@ func Setup(opts *cnf.Options) (err error) {
routes(s) routes(s)
s.SetName("web") s.SetName("web")
s.SetIdleTimeout("650s") s.SetIdleTimeout("650s")
s.SetReadTimeout("10s")
s.SetWriteTimeout("10s")
s.SetHTTPErrorHandler(errors) s.SetHTTPErrorHandler(errors)
s.Logger().SetLogger(log.Instance()) s.Logger().SetLogger(log.Instance())