mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-23 08:04:10 +00:00
Improve stacking
Co-Authored-By: RW <renewerner87@googlemail.com>
This commit is contained in:
parent
90df05dd3a
commit
7aba20b3a3
20
ctx.go
20
ctx.go
@ -34,8 +34,8 @@ import (
|
|||||||
type Ctx struct {
|
type Ctx struct {
|
||||||
app *App // Reference to *App
|
app *App // Reference to *App
|
||||||
route *Route // Reference to *Route
|
route *Route // Reference to *Route
|
||||||
index int // Index of the current handler in the stack
|
indexRoute int // Index of the current route
|
||||||
next bool // Bool to continue to the next handler
|
indexHandler int // Index of the current handler
|
||||||
method string // HTTP method
|
method string // HTTP method
|
||||||
path string // Prettified HTTP path
|
path string // Prettified HTTP path
|
||||||
pathOriginal string // Original HTTP path
|
pathOriginal string // Original HTTP path
|
||||||
@ -78,8 +78,9 @@ func (app *App) AcquireCtx(fctx *fasthttp.RequestCtx) *Ctx {
|
|||||||
ctx := app.pool.Get().(*Ctx)
|
ctx := app.pool.Get().(*Ctx)
|
||||||
// Set app reference
|
// Set app reference
|
||||||
ctx.app = app
|
ctx.app = app
|
||||||
// Set stack index
|
// Reset route and handler index
|
||||||
ctx.index = -1
|
ctx.indexRoute = -1
|
||||||
|
ctx.indexHandler = 0
|
||||||
// Set paths
|
// Set paths
|
||||||
ctx.path = getString(fctx.URI().Path())
|
ctx.path = getString(fctx.URI().Path())
|
||||||
ctx.pathOriginal = ctx.path
|
ctx.pathOriginal = ctx.path
|
||||||
@ -577,9 +578,18 @@ func (ctx *Ctx) Next(err ...error) {
|
|||||||
if len(err) > 0 {
|
if len(err) > 0 {
|
||||||
ctx.err = err[0]
|
ctx.err = err[0]
|
||||||
}
|
}
|
||||||
ctx.next = true
|
|
||||||
|
// Increment handler index
|
||||||
|
ctx.indexHandler++
|
||||||
|
// Did we executed all route handlers?
|
||||||
|
if ctx.indexHandler < len(ctx.route.Handlers) {
|
||||||
|
// Continue route stack
|
||||||
|
ctx.route.Handlers[ctx.indexHandler](ctx)
|
||||||
|
} else {
|
||||||
|
// Continue handler stack
|
||||||
ctx.app.next(ctx)
|
ctx.app.next(ctx)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OriginalURL contains the original request URL.
|
// OriginalURL contains the original request URL.
|
||||||
func (ctx *Ctx) OriginalURL() string {
|
func (ctx *Ctx) OriginalURL() string {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user