1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Format from Accept headers have higher precedence than path extension format

This commit is contained in:
Jorge Bejar 2015-12-29 12:41:57 -03:00
parent 9a85da9367
commit 44ca804229
2 changed files with 11 additions and 2 deletions

View file

@ -67,10 +67,10 @@ module ActionDispatch
v = if params_readable
Array(Mime[parameters[:format]])
elsif extension_format = format_from_path_extension
[extension_format]
elsif use_accept_header && valid_accept_header
accepts
elsif extension_format = format_from_path_extension
[extension_format]
elsif xhr?
[Mime[:js]]
else

View file

@ -909,6 +909,15 @@ class RequestFormat < BaseRequestTest
assert_equal [Mime[:html]], request.formats
end
end
test "formats from accept headers have higher precedence than path extension" do
request = stub_request 'HTTP_ACCEPT' => 'application/json',
'PATH_INFO' => '/foo.xml'
assert_called(request, :parameters, times: 1, returns: {}) do
assert_equal [Mime[:json]], request.formats
end
end
end
class RequestMimeType < BaseRequestTest