1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-21 20:07:04 +00:00

new Timeout, TimeoutMessage configuration fields and apps.OnApplicationRegistered listener

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-12-09 14:44:03 +02:00
parent 968a9ec06c
commit d6cfe3fe5b
9 changed files with 124 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import (
"sort"
"strings"
"sync"
"time"
"github.com/kataras/iris/v12/context"
@@ -271,6 +272,25 @@ func (router *Router) Downgraded() bool {
return router.mainHandler != nil && router.requestHandler == nil
}
// SetTimeoutHandler overrides the main handler with a timeout handler.
//
// TimeoutHandler supports the Pusher interface but does not support
// the Hijacker or Flusher interfaces.
//
// All previous registered wrappers and middlewares are still executed as expected.
func (router *Router) SetTimeoutHandler(timeout time.Duration, msg string) {
if timeout <= 0 {
return
}
mainHandler := router.mainHandler
h := func(w http.ResponseWriter, r *http.Request) {
mainHandler(w, r)
}
router.mainHandler = http.TimeoutHandler(http.HandlerFunc(h), timeout, msg).ServeHTTP
}
// WrapRouter adds a wrapper on the top of the main router.
// Usually it's useful for third-party middleware
// when need to wrap the entire application with a middleware like CORS.