kaazing / http2-cache.js

2 stars 11 forks source link

Cannot send request with responseType = "arraybuffer" from IE #70

Closed tejaede closed 7 years ago

tejaede commented 7 years ago

This is the result of an IE quirk. IE does not allow you to set XmlHttpRequest.responseType before calling XmlHttpRequest.open(). As described here: https://stackoverflow.com/questions/20760635/why-does-setting-xmlhttprequest-responsetype-before-calling-open-throw

http2-cache overwrites XmlHttpRequest.open() and so the native open function is not called immediately. http2-cache does not also defer the setting of XmlHttpRequest.responseType so a snippet like the following results in responseType being set before the native open is called.

var myIconURL = "https://example.com/icon",
      request = new XMLHttpRequest();
request.open("get", myIconURL, true); //intercepted by http2-cache. Native open is called later
request.responseType = "arraybuffer"; //not intercepted. Set immediately. 
request.onload = function () { callback(request.response); };
request.send();
tejaede commented 7 years ago

@hthetiot Similar behavior occurs with XHR.timeout.

var req = new XMLHttpRequest();
req.open("GET", url);
req.addEventListener("load", resolve, false);
req.addEventListener("error", resolve, false);
req.addEventListener("timeout", resolve, false);
req.timeout = self._SCRIPT_TIMEOUT; //Throws Invalid State Error
req.send();
req.listener = resolve;
hthetiot commented 7 years ago

Fixed by #69