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

Closed
ogeidix opened this Issue Jul 17, 2011 · 3 comments

Comments

Projects
None yet
1 participant
@ogeidix
Contributor

ogeidix commented Jul 17, 2011

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

This comment has been minimized.

Show comment Hide comment
@ogeidix

ogeidix Jul 17, 2011

Contributor

I proposed a pull request. See issue #2120

Contributor

ogeidix commented Jul 17, 2011

I proposed a pull request. See issue #2120

ogeidix added a commit to ogeidix/rails that referenced this issue Jul 19, 2011

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.
@ogeidix

This comment has been minimized.

Show comment Hide comment
@ogeidix

ogeidix Jul 19, 2011

Contributor

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

Thanks

Contributor

ogeidix commented Jul 19, 2011

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

Thanks

spastorino added a commit that referenced this issue Jul 20, 2011

Merge pull request #2159 from ogeidix/master
Fixed issue #2119: XHR without Accept and Content-Type header gets 500 error
@ogeidix

This comment has been minimized.

Show comment Hide comment
@ogeidix

ogeidix Jul 21, 2011

Contributor

Thanks @spastorino!

Contributor

ogeidix commented Jul 21, 2011

Thanks @spastorino!

@ogeidix ogeidix closed this Jul 21, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment