New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search action using method argument #3
Conversation
mrblib/shelf/dispatcher.rb
Outdated
@@ -43,8 +43,9 @@ def initialize(map = {}) | |||
def call(env) | |||
path = env[PATH_INFO] | |||
method = R3.method_code(env[REQUEST_METHOD]) | |||
raise ArgumentError, "Invalid HTTP method: #{env[REQUEST_METHOD].inspect}." unless method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, if we get an invalid HTTP request method, Shelf raises confusing an error like TypeError: can't convert nil to Integer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should also result in an HTTP 405
response instead of an server exception
test/builder.rb
Outdated
@@ -139,7 +139,17 @@ def self.env_for(uri = '', opts = {}) | |||
assert_equal 200, app.call(env_for('/any', method: 'PUT'))[0] | |||
assert_equal 200, app.call(env_for('/any', method: 'GET'))[0] | |||
assert_equal 200, app.call(env_for('/put', method: 'PUT'))[0] | |||
assert_equal 405, app.call(env_for('/put', method: 'GET'))[0] | |||
assert_equal 404, app.call(env_for('/put', method: 'GET'))[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think HTTP 405 method not allowed
should be returned in that case
@katzer |
If we define two actions with the same path but a different method, requests pointing to the path result in unintuitive behavior:
This is because, in dispatching requests, Shelf's current implementation does not pass
method
toR3::Tree#match
.In order to fix this issue, I modified Dispatcher to use
method
in addition topath
to match@tree
.