Method Matching - 405 Error Handling #56
Merged
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.
These are my proposed changes for issue #50
I followed your (@chriso) testing model to make sure I wasn't slowing down the router with any of the extra logic. The performance is still amazing, as usual.
Essentially, what this code does, is it keeps track of each HTTP Method that is found in any of the matching routes, and passes that data along with each closure.
It also defaults to sending a 405 HTTP code when it finds that 1 or more of the routers/responders COULD have matched, if it hadn't had been for using the wrong HTTP Method.
I made sure to enable a 405 route match, so that anyone using the library could override/change/etc the behavior of the router when a 405 occurs.
Error Code Reference - http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error