mirror of https://github.com/gofiber/fiber.git
Add 405 Support
parent
3187472744
commit
09116ae22b
2
app.go
2
app.go
|
@ -222,7 +222,7 @@ func New(settings ...*Settings) *App {
|
|||
// Create a new app
|
||||
app := &App{
|
||||
// Create router stack
|
||||
stack: make([][]*Route, len(methodINT)+1),
|
||||
stack: make([][]*Route, len(methodINT)),
|
||||
// Create Ctx pool
|
||||
pool: sync.Pool{
|
||||
New: func() interface{} {
|
||||
|
|
23
utils.go
23
utils.go
|
@ -18,30 +18,37 @@ import (
|
|||
// Scan stack if other methods match
|
||||
func setMethodNotAllowed(ctx *Ctx) {
|
||||
original := getString(ctx.Fasthttp.Request.Header.Method())
|
||||
for m := range methodINT {
|
||||
var match bool
|
||||
for k, v := range methodINT {
|
||||
// Skip original method
|
||||
if m == original {
|
||||
if k == original {
|
||||
continue
|
||||
}
|
||||
// Reset stack index
|
||||
ctx.indexRoute = -1
|
||||
// Set new method
|
||||
ctx.method = m
|
||||
ctx.method = k
|
||||
// Get stack length
|
||||
lenr := len(ctx.app.stack[9]) - 1
|
||||
// Loop over the route stack starting from previous index
|
||||
lenr := len(ctx.app.stack[v]) - 1
|
||||
//Loop over the route stack starting from previous index
|
||||
for ctx.indexRoute < lenr {
|
||||
// Increment route index
|
||||
ctx.indexRoute++
|
||||
// Get *Route
|
||||
route := ctx.app.stack[9][ctx.indexRoute]
|
||||
route := ctx.app.stack[v][ctx.indexRoute]
|
||||
// Check if it matches the request path
|
||||
match, _ := route.match(ctx.path, ctx.pathOriginal)
|
||||
match, _ = route.match(ctx.path, ctx.pathOriginal)
|
||||
// No match, next route
|
||||
if match {
|
||||
ctx.SendStatus(StatusMethodNotAllowed)
|
||||
ctx.Vary(HeaderAllow, m)
|
||||
ctx.Append(HeaderAllow, k)
|
||||
break
|
||||
}
|
||||
}
|
||||
if match {
|
||||
match = false
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue