feat: respond 405 Method Not Allowed instead of 404 - #86
Merged
Merged
Conversation
rayblair06
force-pushed
the
feat/method-not-allowed
branch
from
September 12, 2026 09:52
37cc2af to
022d9d9
Compare
Owner
|
Nice! 😊 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A request to a registered path with an unregistered method returned
404 Not Found. FastRoute reportsMETHOD_NOT_ALLOWEDalong with the methods that path accepts, butRouter::findRoute()discarded that and returnednull, whichhandle()could not tell apart from a genuinely missing route.POST /userson a GET-only route now returns:Unknown paths still return 404.
Changes
Router::dispatch()returns['route' => array|null, 'allowedMethods' => string[]].findRoute()is now a wrapper over it and keeps its existing contract, so nothing that calls it needs to change.Dumbo::handle()returns a 405 with anAllowheader when the path matched but the method did not. Like the 404, it runs through the middleware stack, so CORS and logging still apply.Behaviour change
This is the one thing worth a second opinion. Hono returns 404 for a method mismatch, so if you'd rather match Hono, I'm happy to close this. 405 with
Allowis what RFC 9110 calls for, and what modern PHP frameworks like Slim and Laravel do.Allowlists only the methods actually registered for the path. It does not addHEADfor GET routes, even though HEAD works via FastRoute's fallback. Happy to add that if you'd prefer.Testing
Router::dispatch()for a method mismatch, an unknown path and a normal matchAllowheaderAllowheaderphp -Sand curl.