Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

XHR Req without Accept and Content-Type header gets 500 error #2119

Closed
ogeidix opened this Issue · 3 comments

1 participant

@ogeidix

When actionpack receives an http request with the header X-Requested-With:XMLHttpRequest but without the headers Accept: ... and Content-Type: ... then it blows up.

The problem is generated because in the scenario just described request.formats becomes [nil] instead of a default
["text/html"]

To reproduce the bug you can use curl

curl -H "X-Requested-With:XMLHttpRequest" -H "Accept: " -H "Content-Type: " -v http://127.0.0.1:3000

I wrote a simple test to add to test/dispatch/request_test.rb

test "formats with xhr request"
  request = stub_request 'HTTP_X_REQUESTED_WITH' => "XMLHttpRequest"
  request.expects(:parameters).at_least_once.returns({})
  assert_equal [Mime::HTML], request.formats
end
@ogeidix

I proposed a pull request. See issue #2120

@ogeidix ogeidix referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@ogeidix ogeidix referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@ogeidix ogeidix referenced this issue from a commit in ogeidix/rails
@ogeidix ogeidix 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.
1ac802f
@ogeidix

Sorry for the spam :/ it was due to a bandwith problem.
However the last is correct. See pull request #2159

Thanks

@ogeidix ogeidix closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.