Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Can't make a POST request without a Content-Type #636

Closed
thoughtless opened this issue May 7, 2014 · 3 comments
Closed

Can't make a POST request without a Content-Type #636

thoughtless opened this issue May 7, 2014 · 3 comments

Comments

@thoughtless
Copy link

This seems related to #260

When I make ajax requests with jQuery via capybara-webkit, something is setting the content type to application/json, text/javascript, */*; q=0.01.

The following is an example of an AJAX request gets that Content-Type.

js = "window.my_request = $.ajax({type: 'POST', url: 'http://127.0.0.1:5000/my/path', dataType: 'json', headers: {'X-HTTP-Method-Override': 'DELETE'}})\; window.my_var"
page.evaluate_script(js)

However, when I run the same JavaScript from within Chrome, Firefox, or Safari, none of them add a Content-Type.

I know that POST requests should usually have a Content-Type. However, when a POST request has no body, it doesn't need a Content-Type. In my case I am using a header to better support browsers that can't handle DELETE requests. It is normal for a DELETE request to have no body (and thus no Content-Type).

It looks like the latest from Qt seems to insist on a Content-Type too: https://qt.gitorious.org/qt/qtbase/source/70accc289a077b2d05250676ed33369eeaa7df49:src/network/access/qhttpnetworkrequest.cpp#L162
However that code doesn't explain the Content-Type I am seeing.

@calleluks
Copy link

Hey @thoughtless, does adding the Content-Type header change the semantics of the request? Is it causing problems?

@thoughtless
Copy link
Author

Unfortunately it has been too long since I opened the issue to remember exactly why I cared about this enough to write it up. I tried looking back through the old code, but I can't give you a firm answer. I suspect it had to do with Ruby on Rails executing slightly different controller code. It may also have been causing some issues with Rack Lint.

Since nobody else has commented on this issue in the last year, you might as well close it.

@calleluks
Copy link

Thanks @thoughtless!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants