Fix #1224 by searching routes after failed match
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.
(Also, compared to earlier PRs, this approach only adds runtime overhead when routes fail to match.)
@jespersm Thank you for your contribution! Is there still something missing except rebasing?
@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.
No stress, thank you for your work when you have time 😅