Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 Route with no match returns 200 #430

Closed
mewben opened this issue Jun 1, 2020 · 3 comments
Closed

🐞 Route with no match returns 200 #430

mewben opened this issue Jun 1, 2020 · 3 comments

Comments

@mewben
Copy link

mewben commented Jun 1, 2020

Fiber version/commit
v1.10.1

Issue description
Please see sample code below. It returns 200 for any route. I tried removing all the middleware, it now correctly returns 404. Perhaps there's a breaking change in the way middleware is implemented?

Expected behavior
Should it return 404 instead? or is this the intended behaviour?

Steps to reproduce
Any path e.g. localhost:3000/any-path returns 200
Try removing the app.Use blocks, it correctly returns 404

Code snippet

// Code snippet taken from the readme
package main

import (
	"fmt"

	"github.com/gofiber/fiber"
)

func main() {
	app := fiber.New()

	// Match any route
	app.Use(func(c *fiber.Ctx) {
		fmt.Println("First middleware")
		c.Next()
	})

	// Match all routes starting with /api
	app.Use("/api", func(c *fiber.Ctx) {
		fmt.Println("Second middleware")
		c.Next()
	})

	// GET /api/register
	app.Get("/api/list", func(c *fiber.Ctx) {
		fmt.Println("Last middleware")
		c.Send("Hello, World!")
	})

	app.Listen(3000)
}
@welcome
Copy link

welcome bot commented Jun 1, 2020

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@Fenny
Copy link
Member

Fenny commented Jun 1, 2020

Hi @mewben, thanks for your detailed report.

Your first app.Use theoretically matches the /match-anything path and therefore it defaults to 200.
I had a discussion with the Team and we agreed to change this behavior to return a 404 if c.Next() has no match.

We are currently adding good test cases to make sure we won't break anything when we change this.

@Fenny Fenny mentioned this issue Jun 1, 2020
@Fenny
Copy link
Member

Fenny commented Jun 1, 2020

@mewben the c.Next() behaviour has been adjusted in v1.10.3 so that a proper 404 is set when no match is found in the chain. Thank you for your issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants