Skip to content

Commit

Permalink
Merge pull request #560 from kiyonlin/master
Browse files Browse the repository at this point in the history
🔧 fix #556
  • Loading branch information
Fenny authored Jul 8, 2020

Verified

This commit was signed with the committer’s verified signature.
2 parents 40c7686 + d047f1a commit 9457503
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
@@ -30,6 +30,10 @@ func testStatus200(t *testing.T, app *App, url string, method string) {
func Test_App_MethodNotAllowed(t *testing.T) {
app := New()

// https://github.com/gofiber/fiber/issues/556
// Middleware handler matched will effect setMethodNotAllowed
app.Use(func(ctx *Ctx) { ctx.Next() })

app.Post("/", func(c *Ctx) {})

resp, err := app.Test(httptest.NewRequest("GET", "/", nil))
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ func (app *App) handler(rctx *fasthttp.RequestCtx) {
setETag(ctx, false)
}
// Scan stack for other methods
if !match {
if ctx.Fasthttp.Response.StatusCode() == StatusNotFound {
setMethodNotAllowed(ctx)
}
// Release Ctx
4 changes: 4 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
@@ -36,6 +36,10 @@ func setMethodNotAllowed(ctx *Ctx) {
ctx.indexRoute++
// Get *Route
route := ctx.app.stack[i][ctx.indexRoute]
// Skip use routes
if route.use {
continue
}
// Check if it matches the request path
match, _ := route.match(ctx.path, ctx.pathOriginal)
// No match, next route

3 comments on commit 9457503

@Fenny
Copy link
Member Author

@Fenny Fenny commented on 9457503 Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 9457503 Previous: 40c7686 Ratio
Benchmark_Router_NotFound 14180 ns/op 83 B/op 2 allocs/op 1139 ns/op 80 B/op 2 allocs/op 12.45

This comment was automatically generated by workflow using github-action-benchmark.

@Fenny
Copy link
Member Author

@Fenny Fenny commented on 9457503 Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 9457503 Previous: 40c7686 Ratio
Benchmark_Router_NotFound 13642 ns/op 82 B/op 2 allocs/op 1139 ns/op 80 B/op 2 allocs/op 11.98

This comment was automatically generated by workflow using github-action-benchmark.

@Fenny
Copy link
Member Author

@Fenny Fenny commented on 9457503 Jul 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 9457503 Previous: 40c7686 Ratio
Benchmark_Router_NotFound 11723 ns/op 82 B/op 2 allocs/op 1139 ns/op 80 B/op 2 allocs/op 10.29

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.