Custom headers impossible with XDomainRequest (IE8/9) #159
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Enyo-DCO-1.0-Signed-off-by: Nicolas Rempulski nicolas.rempulski@ubidreams.com
Edit : sorry about this slip, yet I read the contribute page !