Skip to content

Commit

Permalink
Merge pull request #25798 from greysteil/dont-raise-unknown-http-meth…
Browse files Browse the repository at this point in the history
…od-low-in-stack

Don't raise ActionController::UnknownHttpMethod from ActionDispatch::Static
  • Loading branch information
matthewd authored and rafaelfranca committed Jul 17, 2016
1 parent 666b2c7 commit ffa13e9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions actionpack/CHANGELOG.md
@@ -1,3 +1,12 @@
* Don't raise ActionController::UnknownHttpMethod from ActionDispatch::Static

Pass `Rack::Request` objects to `ActionDispatch::FileHandler` to avoid it
raising `ActionController::UnknownHttpMethod`. If an unknown method is
passed, it should exception higher in the stack instead, once we've had a
chance to define exception handling behaviour.

*Grey Baker*

* Handle `Rack::QueryParser` errors in `ActionDispatch::ExceptionWrapper`

Updated `ActionDispatch::ExceptionWrapper` to handle the Rack 2.0 namespace
Expand Down
6 changes: 3 additions & 3 deletions actionpack/lib/action_dispatch/middleware/static.rb
Expand Up @@ -46,7 +46,7 @@ def match?(path)
end

def call(env)
serve ActionDispatch::Request.new env
serve(Rack::Request.new(env))
end

def serve(request)
Expand Down Expand Up @@ -82,7 +82,7 @@ def content_type(path)
end

def gzip_encoding_accepted?(request)
request.accept_encoding =~ /\bgzip\b/i
request.accept_encoding.any? { |enc, quality| enc =~ /\bgzip\b/i }
end

def gzip_file_path(path)
Expand Down Expand Up @@ -123,7 +123,7 @@ def initialize(app, path, deprecated_cache_control = :not_set, index: 'index', h
end

def call(env)
req = ActionDispatch::Request.new env
req = Rack::Request.new env

if req.get? || req.head?
path = req.path_info.chomp('/'.freeze)
Expand Down
9 changes: 9 additions & 0 deletions actionpack/test/dispatch/static_test.rb
Expand Up @@ -160,6 +160,9 @@ def test_serves_gzip_files_when_header_set
response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'GZIP')
assert_gzip file_name, response

response = get(file_name, 'HTTP_ACCEPT_ENCODING' => 'compress;q=0.5, gzip;q=1.0')
assert_gzip file_name, response

response = get(file_name, 'HTTP_ACCEPT_ENCODING' => '')
assert_not_equal 'gzip', response.headers["Content-Encoding"]
end
Expand Down Expand Up @@ -205,6 +208,12 @@ def test_serves_files_with_headers
assert_equal "I'm a teapot", response.headers["X-Custom-Header"]
end

def test_ignores_unknown_http_methods
app = ActionDispatch::Static.new(DummyApp, @root)

assert_nothing_raised { Rack::MockRequest.new(app).request("BAD_METHOD", "/foo/bar.html") }
end

# Windows doesn't allow \ / : * ? " < > | in filenames
unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
def test_serves_static_file_with_colon
Expand Down

0 comments on commit ffa13e9

Please sign in to comment.