mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
nothing special here
This commit is contained in:
parent
2cb0d9981d
commit
d00bd8e595
10
http.go
10
http.go
|
@ -1335,8 +1335,9 @@ type (
|
|||
}
|
||||
|
||||
serveMux struct {
|
||||
tree *muxTree
|
||||
lookups []*route
|
||||
tree *muxTree
|
||||
lookups []*route
|
||||
maxParameters uint8
|
||||
|
||||
onLookup func(Route)
|
||||
|
||||
|
@ -1454,6 +1455,7 @@ func (mux *serveMux) build() (func(reqCtx *fasthttp.RequestCtx) string, func([]b
|
|||
if tree == nil {
|
||||
//first time we register a route to this method with this domain
|
||||
tree = &muxTree{method: r.method, subdomain: r.subdomain, entry: &muxEntry{}, next: nil}
|
||||
|
||||
if mux.tree == nil {
|
||||
// it's the first entry
|
||||
mux.tree = tree
|
||||
|
@ -1474,6 +1476,10 @@ func (mux *serveMux) build() (func(reqCtx *fasthttp.RequestCtx) string, func([]b
|
|||
if err := tree.entry.add(r.path, r.middleware); err != nil {
|
||||
mux.logger.Panic(err.Error())
|
||||
}
|
||||
|
||||
if mp := tree.entry.paramsLen; mp > mux.maxParameters {
|
||||
mux.maxParameters = mp
|
||||
}
|
||||
}
|
||||
|
||||
// optimize this once once, we could do that: context.RequestPath(mux.escapePath), but we lose some nanoseconds on if :)
|
||||
|
|
23
iris.go
23
iris.go
|
@ -238,11 +238,11 @@ func New(setters ...OptionSetter) *Framework {
|
|||
// set the servemux, which will provide us the public API also, with its context pool
|
||||
mux := newServeMux(s.Logger)
|
||||
mux.onLookup = s.Plugins.DoPreLookup
|
||||
s.contextPool.New = func() interface{} {
|
||||
return &Context{framework: s, Params: make(PathParameters, s.mux.maxParameters)}
|
||||
}
|
||||
// set the public router API (and party)
|
||||
s.muxAPI = &muxAPI{mux: mux, relativePath: "/"}
|
||||
s.contextPool.New = func() interface{} {
|
||||
return &Context{framework: s}
|
||||
}
|
||||
s.Servers = &ServerList{mux: mux, servers: make([]*Server, 0)}
|
||||
s.Available = make(chan bool)
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ func (s *Framework) initialize() {
|
|||
// prepare the mux & the server
|
||||
s.mux.setCorrectPath(!s.Config.DisablePathCorrection)
|
||||
s.mux.setEscapePath(!s.Config.DisablePathEscape)
|
||||
|
||||
// set the debug profiling handlers if ProfilePath is setted
|
||||
if debugPath := s.Config.ProfilePath; debugPath != "" {
|
||||
s.Handle(MethodGet, debugPath+"/*action", profileMiddleware(debugPath)...)
|
||||
|
@ -298,15 +299,15 @@ func (s *Framework) initialize() {
|
|||
if s.Config.CheckForUpdatesSync {
|
||||
s.CheckForUpdates(false)
|
||||
} else if s.Config.CheckForUpdates {
|
||||
go func() { s.CheckForUpdates(false) }()
|
||||
go s.CheckForUpdates(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// AcquireCtx gets an Iris' Context from pool
|
||||
// see iris.Handler & ReleaseCtx, Go()
|
||||
func AcquireCtx(reqCtx *fasthttp.RequestCtx) {
|
||||
Default.AcquireCtx(reqCtx)
|
||||
func AcquireCtx(reqCtx *fasthttp.RequestCtx) *Context {
|
||||
return Default.AcquireCtx(reqCtx)
|
||||
}
|
||||
|
||||
// ReleaseCtx puts the Iris' Context back to the pool in order to be re-used
|
||||
|
@ -347,15 +348,9 @@ func (s *Framework) Go() error {
|
|||
serve := s.mux.BuildHandler()
|
||||
// build the fasthttp handler to bind it to the servers
|
||||
defaultHandler := func(reqCtx *fasthttp.RequestCtx) {
|
||||
ctx := s.contextPool.Get().(*Context) // Changed to use the pool's New 09/07/2016, ~ -4k nanoseconds(9 bench tests) per requests (better performance)
|
||||
ctx.RequestCtx = reqCtx
|
||||
|
||||
ctx := s.AcquireCtx(reqCtx)
|
||||
serve(ctx)
|
||||
|
||||
ctx.Params = ctx.Params[0:0]
|
||||
ctx.middleware = nil
|
||||
ctx.session = nil
|
||||
s.contextPool.Put(ctx)
|
||||
s.ReleaseCtx(ctx)
|
||||
}
|
||||
|
||||
s.Handler = defaultHandler
|
||||
|
|
Loading…
Reference in New Issue
Block a user