Rocket icon indicating copy to clipboard operation
Rocket copied to clipboard

Fix #1224 by searching routes after failed match

Open jespersm opened this issue 2 years ago • 6 comments

This PR fixes #1224 by introducing more detailed HTTP status reporting.

If the request is matched, this patch does nothing. That way, routes which set their own HTTP status code are not affected even if they return 404.

If no route matches the request, this PR checks for "near matches", first looking to see if any routes failed only the format check, and afterwards checks for matching paths, but on a different HTTP method.

For format-check failures for POST and PUT, the HTTP status code will be 415 Unsupported Media Type (since this means that the Content-Type of the request didn't match what the route expected). For GET, etc., a failed format check will be 406 Not Acceptable, since the route couldn't produce what the client requested.

If the method and path didn't match at all, but the path is present as a route for one of the other HTTP methods, 405 Method Not Allowed is returned.

Otherwise, the 404 Not Found is left as is.

Tests were corrected as required.

jespersm avatar Sep 20 '23 00:09 jespersm

(Also, compared to earlier PRs, this approach only adds runtime overhead when routes fail to match.)

jespersm avatar Sep 20 '23 00:09 jespersm

@jespersm Thank you for your contribution! Is there still something missing except rebasing?

reneleonhardt avatar Jul 27 '24 20:07 reneleonhardt

@jespersm Thank you for your contribution! Is there still something missing except rebasing?

Ouch, I'm not sure, and I'm AFK for a few days, so I can't really check or rebase at the moment.

jespersm avatar Jul 28 '24 15:07 jespersm

No stress, thank you for your work when you have time 😅

reneleonhardt avatar Jul 28 '24 16:07 reneleonhardt