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
|
// Create a new app
|
||||||
app := &App{
|
app := &App{
|
||||||
// Create router stack
|
// Create router stack
|
||||||
stack: make([][]*Route, len(methodINT)+1),
|
stack: make([][]*Route, len(methodINT)),
|
||||||
// Create Ctx pool
|
// Create Ctx pool
|
||||||
pool: sync.Pool{
|
pool: sync.Pool{
|
||||||
New: func() interface{} {
|
New: func() interface{} {
|
||||||
|
|
23
utils.go
23
utils.go
|
@ -18,30 +18,37 @@ import (
|
||||||
// Scan stack if other methods match
|
// Scan stack if other methods match
|
||||||
func setMethodNotAllowed(ctx *Ctx) {
|
func setMethodNotAllowed(ctx *Ctx) {
|
||||||
original := getString(ctx.Fasthttp.Request.Header.Method())
|
original := getString(ctx.Fasthttp.Request.Header.Method())
|
||||||
for m := range methodINT {
|
var match bool
|
||||||
|
for k, v := range methodINT {
|
||||||
// Skip original method
|
// Skip original method
|
||||||
if m == original {
|
if k == original {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Reset stack index
|
// Reset stack index
|
||||||
ctx.indexRoute = -1
|
ctx.indexRoute = -1
|
||||||
// Set new method
|
// Set new method
|
||||||
ctx.method = m
|
ctx.method = k
|
||||||
// Get stack length
|
// Get stack length
|
||||||
lenr := len(ctx.app.stack[9]) - 1
|
lenr := len(ctx.app.stack[v]) - 1
|
||||||
// Loop over the route stack starting from previous index
|
//Loop over the route stack starting from previous index
|
||||||
for ctx.indexRoute < lenr {
|
for ctx.indexRoute < lenr {
|
||||||
|
// Increment route index
|
||||||
|
ctx.indexRoute++
|
||||||
// Get *Route
|
// Get *Route
|
||||||
route := ctx.app.stack[9][ctx.indexRoute]
|
route := ctx.app.stack[v][ctx.indexRoute]
|
||||||
// Check if it matches the request path
|
// 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
|
// No match, next route
|
||||||
if match {
|
if match {
|
||||||
ctx.SendStatus(StatusMethodNotAllowed)
|
ctx.SendStatus(StatusMethodNotAllowed)
|
||||||
ctx.Vary(HeaderAllow, m)
|
ctx.Append(HeaderAllow, k)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if match {
|
||||||
|
match = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue