Fiber: ๐Ÿž Route with no match returns 200

Created on 1 Jun 2020  ยท  3Comments  ยท  Source: gofiber/fiber

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)
}

โ™ป Wait for Response

Most helpful comment

@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 ๐Ÿ‘

All 3 comments

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

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.

@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 ๐Ÿ‘

Was this page helpful?
0 / 5 - 0 ratings