enyojs/enyo — pull request #159 by nicolas-rempulski (2012-10-23 22:41:38+00:00)
Title: Custom headers impossible with XDomainRequest (IE8/9) 

XDomainRequest objects cannot be set with custom headers (especially content-type). XDomainRequest.contentType is a read-only field (getter) :

http://msdn.microsoft.com/en-us/library/ie/cc288060(v=vs.85).aspx

The reason behind this is security, as stated in this msdn blog entry (point 4) :

http://blogs.msdn.com/b/ieinternals/archive/2010/05/13/xdomainrequest-restrictions-limitations-and-workarounds.aspx.

But on xhr.js [getXMLHttpRequest] function, the decision between XDomainRequest and XmlHttpRequest do not check if the request parameters specify headers. So if inParam.headers is set with some custom headers, in a XDomain scenario, [request] function would try to set them with :

xhr.setRequestHeader(key, inParams.headers[key]);

But the function setRequestHeader is not defined for XDomainRequest objects.

Thus I propose to patch xhr.js in two points :

1)Passing all request params to [getXMLHttpRequest] to allow a fallback to XMLHttpRequest object in case inParams.headers are set.

2)Checking the definition of xhr.setRequestHeader before setting header, thus preventing an exception if the xhr variable is a XDomainRequest.