-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
middleware + group => 404 is returned when 405 should be returned #1981
Comments
I took a stab at it but without a lot of knowledge of all the edge cases of the rather complex router code I have no idea if it's a good one. tree: https://github.com/Gundersanne/echo/tree/1981
|
Probably is related to Lines 28 to 29 in 7f502b1
when group is created it adds 2 routes so middlewares will be executed for that group in case of 404 |
Ah, that seems weird to me, returning the |
well it depends. for router match created by I'll have to investigate this situation. |
Ah I get that, but I'm not sure if it should take priority over the exact path match as in the reproducer. Note that with this patch calling the group point ( |
If you comment out //g.Any("", NotFoundHandler)
//g.Any("/*", NotFoundHandler) you would get 405 but this means that your Logger middleware will not be fired for that request. When logger is added with just a note - group is pretty much helper for adding routes with same prefix and middlewares. it does not exist as a separate entity. |
Right, but with With edit: Not entirely sure I follow, but I think I see your point. But in the case of calling the group endpoint directly, |
well, removing those 2 lines would probably be surprise after update for some (probably rare cases?). We are planning to remove those lines in
For example: e := echo.New()
g := e.Group("/api")
g.Use(middleware.Logger())
e.Start(":8080") has 2 routes in runtime
|
Yea and I think that behaviour remains intact for 584291d. The commit message isn't entirely correct however, really it should be something like:
Removing the two For instance:
With a nested group you'd expect a call to
In this case a call to
Which is what you'd expect right, it matches |
Was a workaround ever found for this issue ? |
It is not but I think we can fix this by replacing Lines 28 to 30 in 40eb889
with (probably the most correct in this situation as g.RouteNotFound("", NotFoundHandler)
g.RouteNotFound("/*", NotFoundHandler) and maybe add new method I'll create PR for this |
Issue Description
When using a middleware in combination with a group, 404 is returned when 405 should be returned.
Checklist
Expected behaviour
Return 405 when calling the endpoint behind the group with a wrong method.
Actual behaviour
Received 404.
Steps to reproduce
minimal reproducer:
in a shell:
->{"message":"Not Found"}
Version/commit
This was broken in 6430665, released in 4.3.0 and onward
The text was updated successfully, but these errors were encountered: