diff options
author | Jorge Bejar <jorge@wyeworks.com> | 2015-12-29 12:41:57 -0300 |
---|---|---|
committer | Jorge Bejar <jorge@wyeworks.com> | 2015-12-29 13:43:14 -0300 |
commit | 44ca804229cfdf7a149eed63a2f61f387f6f9fc8 (patch) | |
tree | 96f984dec9fbe8942dfc8a50349f255e00e7a3c7 | |
parent | 9a85da9367eaf65b4232a548ff1f2535ef3496cd (diff) | |
download | rails-44ca804229cfdf7a149eed63a2f61f387f6f9fc8.tar.gz rails-44ca804229cfdf7a149eed63a2f61f387f6f9fc8.tar.bz2 rails-44ca804229cfdf7a149eed63a2f61f387f6f9fc8.zip |
Format from Accept headers have higher precedence than path extension format
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_negotiation.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index eb9c2a18cb..e9b25339dc 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -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 diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 26386d2aa1..0edad72fd9 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -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 |