IE CORS issues with missing Content-Type header

689 views
Skip to first unread message

Wesley Thomas

unread,
Oct 25, 2012, 1:42:24 PM10/25/12
to django-res...@googlegroups.com
I believe I've narrowed down an issue I'm having with IE to a missing Content-Type header.

If I simulate an IE request using curl, I can duplicate this issue:

$ curl -v -H 'Accept: */*' -H 'Content-Type:' -A "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)" -X POST --data 'auth_user_id=1&session_id=asdfasdfasdf1234' http://api.domain.com/api/Auth/BeginSession

Returns:
...snipped...
"error": "Unsupported media type in request ''."
...

Which is perfectly logical because it can't parse the incoming data because there's no Content-Type!


I'm using jQuery's ajax method to make a request and a plugin for jQuery that adds IE8/9 support for CORS using the XDomainRequest object (https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest).

Here's the rub: You can't set custom headers for an XDomainRequest object (!!) See http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx

So I cannot specify Content-Type: application/x-www-urlencoded for my requests coming from IE8/9 so that django-rest-framework can properly decode the request.


Sooo.... can someone tell me how I can rig django-rest-framework to accept the following headers and respond as if it was requested with a valid Content-Type? Yes, I know it's a hack, but I don't really have a choice at this point. And it's an IE hack, which really is just a redundant statement: it's for IE.

If this is documented, please point me in the right direction.



Accept: */*
Accept-Language: en-US
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Content-Length: 42
Connection: Keep-Alive
Pragma: no-cache

auth_user_id=1&session_id=asdfasdfasdf1234




Wes

Tom Christie

unread,
Oct 25, 2012, 5:00:50 PM10/25/12
to django-res...@googlegroups.com
Hey Wes,

  You could override this method, and force a default value for content-type if it's absent:

  If you move to 2.0 anytime, you could do this in a nicer way by providing a custom content negotiation class.

Wesley Thomas

unread,
Oct 25, 2012, 5:10:52 PM10/25/12
to django-res...@googlegroups.com
Yup, I was very near to that. 

I was actually trying to implement a custom Parser that I could specify in my View, but I can't seem to get it working. Something with defining the parsers = (MyClass,) that causes an error.

I also tried the content overrides with _content and _content_type params in the request but I sill get the same 415 UNSUPPORTED MEDIA TYPE because now it's 'text/plain' for some reason. Grrrr... can't win on this today.
Reply all
Reply to author
Forward
0 new messages