Permalink
Browse files

Check Accept and Content-Type headers before evaluating them in xhr r…

…equests. Closes #2119

An xhr request must have an "Accept" or "Content-type" header in order to be considered a request with valid_accept_header.
  • Loading branch information...
1 parent 37418e5 commit 1ac802fe3c79fc2838253e71e4f32e3f1710f8f1 @ogeidix committed Jul 19, 2011
@@ -98,7 +98,8 @@ def negotiate_mime(order)
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
@@ -468,6 +468,12 @@ def url_for(options = {})
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

0 comments on commit 1ac802f

Please sign in to comment.