stream-http
Advanced tools
Comparing version 2.6.0 to 2.6.1
@@ -9,17 +9,29 @@ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream) | ||
// Service workers don't have XHR | ||
var xhr = null | ||
if (global.XMLHttpRequest) { | ||
xhr = new global.XMLHttpRequest() | ||
// If XDomainRequest is available (ie only, where xhr might not work | ||
// cross domain), use the page location. Otherwise use example.com | ||
// Note: this doesn't actually make an http request. | ||
try { | ||
xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com') | ||
} catch(e) { | ||
// The xhr request to example.com may violate some restrictive CSP configurations, | ||
// so if we're running in a browser that supports `fetch`, avoid calling getXHR() | ||
// and assume support for certain features below. | ||
var xhr | ||
function getXHR () { | ||
// Cache the xhr value | ||
if (xhr !== undefined) return xhr | ||
if (global.XMLHttpRequest) { | ||
xhr = new global.XMLHttpRequest() | ||
// If XDomainRequest is available (ie only, where xhr might not work | ||
// cross domain), use the page location. Otherwise use example.com | ||
// Note: this doesn't actually make an http request. | ||
try { | ||
xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com') | ||
} catch(e) { | ||
xhr = null | ||
} | ||
} else { | ||
// Service workers don't have XHR | ||
xhr = null | ||
} | ||
return xhr | ||
} | ||
function checkTypeSupport (type) { | ||
var xhr = getXHR() | ||
if (!xhr) return false | ||
@@ -38,3 +50,6 @@ try { | ||
exports.arraybuffer = haveArrayBuffer && checkTypeSupport('arraybuffer') | ||
// If fetch is supported, then arraybuffer will be supported too. Skip calling | ||
// checkTypeSupport(), since that calls getXHR(). | ||
exports.arraybuffer = exports.fetch || (haveArrayBuffer && checkTypeSupport('arraybuffer')) | ||
// These next two tests unavoidably show warnings in Chrome. Since fetch will always | ||
@@ -45,3 +60,7 @@ // be used if it's available, just return false for these to avoid the warnings. | ||
checkTypeSupport('moz-chunked-arraybuffer') | ||
exports.overrideMimeType = xhr ? isFunction(xhr.overrideMimeType) : false | ||
// If fetch is supported, then overrideMimeType will be supported too. Skip calling | ||
// getXHR(). | ||
exports.overrideMimeType = exports.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false) | ||
exports.vbArray = isFunction(global.VBArray) | ||
@@ -48,0 +67,0 @@ |
{ | ||
"name": "stream-http", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "Streaming http in the browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
84853
1352