diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2011-07-20 10:29:28 -0700 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2011-07-20 10:29:28 -0700 |
commit | 993d0f6477c6dce4eb207578c1d0970cec859447 (patch) | |
tree | 16b6ffad4e49fd6dc6318c32d8d7000a2769edd0 | |
parent | 64268c5dd1f908aceaecea1a5c61314dd2f2efc3 (diff) | |
parent | 1ac802fe3c79fc2838253e71e4f32e3f1710f8f1 (diff) | |
download | rails-993d0f6477c6dce4eb207578c1d0970cec859447.tar.gz rails-993d0f6477c6dce4eb207578c1d0970cec859447.tar.bz2 rails-993d0f6477c6dce4eb207578c1d0970cec859447.zip |
Merge pull request #2159 from ogeidix/master
Fixed issue #2119: XHR without Accept and Content-Type header gets 500 error
-rw-r--r-- | actionpack/lib/action_dispatch/http/mime_negotiation.rb | 3 | ||||
-rw-r--r-- | actionpack/test/dispatch/request_test.rb | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/mime_negotiation.rb b/actionpack/lib/action_dispatch/http/mime_negotiation.rb index 980c658ab7..5c48a60469 100644 --- a/actionpack/lib/action_dispatch/http/mime_negotiation.rb +++ b/actionpack/lib/action_dispatch/http/mime_negotiation.rb @@ -98,7 +98,8 @@ module ActionDispatch BROWSER_LIKE_ACCEPTS = /,\s*\*\/\*|\*\/\*\s*,/ def valid_accept_header - xhr? || (accept && accept !~ BROWSER_LIKE_ACCEPTS) + (xhr? && (accept || content_mime_type)) || + (accept && accept !~ BROWSER_LIKE_ACCEPTS) end def use_accept_header diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index 25b1b4f745..060bcfb5ec 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -468,6 +468,12 @@ class RequestTest < ActiveSupport::TestCase assert request.formats.empty? end + test "formats with xhr request" do + request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest" + request.expects(:parameters).at_least_once.returns({}) + assert_equal [Mime::JS], request.formats + end + test "ignore_accept_header" do ActionDispatch::Request.ignore_accept_header = true |