stream-http
Advanced tools
Comparing version 2.8.3 to 3.0.0
@@ -7,8 +7,2 @@ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream) | ||
exports.blobConstructor = false | ||
try { | ||
new Blob([new ArrayBuffer(1)]) | ||
exports.blobConstructor = true | ||
} catch (e) {} | ||
// The xhr request to example.com may violate some restrictive CSP configurations, | ||
@@ -49,16 +43,10 @@ // so if we're running in a browser that supports `fetch`, avoid calling getXHR() | ||
// For some strange reason, Safari 7.0 reports typeof global.ArrayBuffer === 'object'. | ||
// Safari 7.1 appears to have fixed this bug. | ||
var haveArrayBuffer = typeof global.ArrayBuffer !== 'undefined' | ||
var haveSlice = haveArrayBuffer && isFunction(global.ArrayBuffer.prototype.slice) | ||
// If fetch is supported, then arraybuffer will be supported too. Skip calling | ||
// checkTypeSupport(), since that calls getXHR(). | ||
exports.arraybuffer = exports.fetch || (haveArrayBuffer && checkTypeSupport('arraybuffer')) | ||
exports.arraybuffer = exports.fetch || checkTypeSupport('arraybuffer') | ||
// These next two tests unavoidably show warnings in Chrome. Since fetch will always | ||
// be used if it's available, just return false for these to avoid the warnings. | ||
exports.msstream = !exports.fetch && haveSlice && checkTypeSupport('ms-stream') | ||
exports.mozchunkedarraybuffer = !exports.fetch && haveArrayBuffer && | ||
checkTypeSupport('moz-chunked-arraybuffer') | ||
exports.msstream = !exports.fetch && checkTypeSupport('ms-stream') | ||
exports.mozchunkedarraybuffer = !exports.fetch && checkTypeSupport('moz-chunked-arraybuffer') | ||
@@ -69,4 +57,2 @@ // If fetch is supported, then overrideMimeType will be supported too. Skip calling | ||
exports.vbArray = isFunction(global.VBArray) | ||
function isFunction (value) { | ||
@@ -73,0 +59,0 @@ return typeof value === 'function' |
@@ -5,3 +5,2 @@ var capability = require('./capability') | ||
var stream = require('readable-stream') | ||
var toArrayBuffer = require('to-arraybuffer') | ||
@@ -20,4 +19,2 @@ var IncomingMessage = response.IncomingMessage | ||
return 'arraybuffer' | ||
} else if (capability.vbArray && preferBinary) { | ||
return 'text:vbarray' | ||
} else { | ||
@@ -36,3 +33,3 @@ return 'text' | ||
if (opts.auth) | ||
self.setHeader('Authorization', 'Basic ' + new Buffer(opts.auth).toString('base64')) | ||
self.setHeader('Authorization', 'Basic ' + Buffer.from(opts.auth).toString('base64')) | ||
Object.keys(opts.headers).forEach(function (name) { | ||
@@ -108,15 +105,6 @@ self.setHeader(name, opts.headers[name]) | ||
if (opts.method !== 'GET' && opts.method !== 'HEAD') { | ||
if (capability.arraybuffer) { | ||
body = toArrayBuffer(Buffer.concat(self._body)) | ||
} else if (capability.blobConstructor) { | ||
body = new global.Blob(self._body.map(function (buffer) { | ||
return toArrayBuffer(buffer) | ||
}), { | ||
type: (headersObj['content-type'] || {}).value || '' | ||
}) | ||
} else { | ||
// get utf8 string | ||
body = Buffer.concat(self._body).toString() | ||
} | ||
} | ||
body = new Blob(self._body, { | ||
type: (headersObj['content-type'] || {}).value || '' | ||
}); | ||
} | ||
@@ -182,3 +170,3 @@ // create flattened list of headers | ||
if ('responseType' in xhr) | ||
xhr.responseType = self._mode.split(':')[0] | ||
xhr.responseType = self._mode | ||
@@ -185,0 +173,0 @@ if ('withCredentials' in xhr) |
@@ -49,3 +49,3 @@ var capability = require('./capability') | ||
reject() | ||
} else if(self.push(new Buffer(chunk))) { | ||
} else if(self.push(Buffer.from(chunk))) { | ||
resolve() | ||
@@ -88,3 +88,3 @@ } else { | ||
} | ||
self.push(new Buffer(result.value)) | ||
self.push(Buffer.from(result.value)) | ||
read() | ||
@@ -158,25 +158,8 @@ }).catch(function (err) { | ||
switch (self._mode) { | ||
case 'text:vbarray': // For IE9 | ||
if (xhr.readyState !== rStates.DONE) | ||
break | ||
try { | ||
// This fails in IE8 | ||
response = new global.VBArray(xhr.responseBody).toArray() | ||
} catch (e) {} | ||
if (response !== null) { | ||
self.push(new Buffer(response)) | ||
break | ||
} | ||
// Falls through in IE8 | ||
case 'text': | ||
try { // This will fail when readyState = 3 in IE9. Switch mode and wait for readyState = 4 | ||
response = xhr.responseText | ||
} catch (e) { | ||
self._mode = 'text:vbarray' | ||
break | ||
} | ||
response = xhr.responseText | ||
if (response.length > self._pos) { | ||
var newData = response.substr(self._pos) | ||
if (self._charset === 'x-user-defined') { | ||
var buffer = new Buffer(newData.length) | ||
var buffer = Buffer.alloc(newData.length) | ||
for (var i = 0; i < newData.length; i++) | ||
@@ -196,3 +179,3 @@ buffer[i] = newData.charCodeAt(i) & 0xff | ||
response = xhr.response | ||
self.push(new Buffer(new Uint8Array(response))) | ||
self.push(Buffer.from(new Uint8Array(response))) | ||
break | ||
@@ -203,3 +186,3 @@ case 'moz-chunked-arraybuffer': // take whole | ||
break | ||
self.push(new Buffer(new Uint8Array(response))) | ||
self.push(Buffer.from(new Uint8Array(response))) | ||
break | ||
@@ -213,3 +196,3 @@ case 'ms-stream': | ||
if (reader.result.byteLength > self._pos) { | ||
self.push(new Buffer(new Uint8Array(reader.result.slice(self._pos)))) | ||
self.push(Buffer.from(new Uint8Array(reader.result.slice(self._pos)))) | ||
self._pos = reader.result.byteLength | ||
@@ -216,0 +199,0 @@ } |
{ | ||
"name": "stream-http", | ||
"version": "2.8.3", | ||
"version": "3.0.0", | ||
"description": "Streaming http in the browser", | ||
@@ -32,10 +32,9 @@ "main": "index.js", | ||
"inherits": "^2.0.1", | ||
"readable-stream": "^2.3.6", | ||
"to-arraybuffer": "^1.0.0", | ||
"readable-stream": "^3.0.6", | ||
"xtend": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"airtap": "^0.0.5", | ||
"basic-auth": "^2.0.0", | ||
"brfs": "^1.6.1", | ||
"airtap": "^0.1.0", | ||
"basic-auth": "^2.0.1", | ||
"brfs": "^2.0.1", | ||
"cookie-parser": "^1.4.3", | ||
@@ -42,0 +41,0 @@ "express": "^4.16.3", |
@@ -25,20 +25,10 @@ # stream-http [![Build Status](https://travis-ci.org/jhiesey/stream-http.svg?branch=master)](https://travis-ci.org/jhiesey/stream-http) | ||
The following browsers support pseudo-streaming, where the data is available before the | ||
request finishes, but the entire response must be held in memory: | ||
* Chrome | ||
* Safari >= 5, and maybe older | ||
* IE >= 10 | ||
* Most other Webkit-based browsers, including the default Android browser | ||
All other supported browsers support pseudo-streaming, where the data is available before | ||
the request finishes, but the entire response must be held in memory. This works for both | ||
text and binary data. | ||
All browsers newer than IE8 support binary responses. All of the above browsers that | ||
support true streaming or pseudo-streaming support that for binary data as well | ||
except for IE10. Old (presto-based) Opera also does not support binary streaming either. | ||
### IE note: | ||
As of version 3.0.0, IE10 and below are no longer supported. IE11 support will remain for | ||
now. | ||
### IE8 note: | ||
As of version 2.0.0, IE8 support requires the user to supply polyfills for | ||
`Object.keys`, `Array.prototype.forEach`, and `Array.prototype.indexOf`. Example | ||
implementations are provided in [ie8-polyfill.js](ie8-polyfill.js); alternately, | ||
you may want to consider using [es5-shim](https://github.com/es-shims/es5-shim). | ||
All browsers with full ES5 support shouldn't require any polyfills. | ||
## How do you use it? | ||
@@ -136,3 +126,5 @@ | ||
you will need to sign up for an account (free for open source projects) and put the | ||
credentials in a [`.zuulrc` file](https://github.com/defunctzombie/zuul/wiki/zuulrc). | ||
credentials in a [`.airtaprc` file](https://github.com/airtap/airtap/blob/master/doc/airtaprc.md). | ||
You will also need to run a [Sauce Connect Proxy](https://wiki.saucelabs.com/display/DOCS/Sauce+Connect+Proxy) | ||
with the same credentials. | ||
@@ -142,3 +134,3 @@ To run just the Node tests, run `npm run test-node`. | ||
To run the browser tests locally, run `npm run test-browser-local` and point your browser to | ||
`http://localhost:8080/__zuul` | ||
the link shown in your terminal. | ||
@@ -145,0 +137,0 @@ ## License |
@@ -8,14 +8,3 @@ var Buffer = require('buffer').Buffer | ||
var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() | ||
var browserName = browser.name | ||
var browserVersion = browser.major | ||
// Binary streaming doesn't work in IE10 or below | ||
var skipStreamingCheck = (browserName === 'IE' && browserVersion <= 10) | ||
// Binary data gets corrupted in IE8 or below | ||
var skipVerification = (browserName === 'IE' && browserVersion <= 8) | ||
// IE8 tends to throw up modal dialogs complaining about scripts running too long | ||
// Since streaming doesn't actually work there anyway, just use one copy | ||
var COPIES = skipVerification ? 1 : 20 | ||
var COPIES = 20 | ||
var MIN_PIECES = 2 | ||
@@ -36,11 +25,4 @@ | ||
res.on('end', function () { | ||
if (skipVerification) | ||
t.skip('binary data not preserved on IE <= 8') | ||
else | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
if (skipStreamingCheck) | ||
t.skip('streaming not available on IE <= 8') | ||
else | ||
t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts') | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts') | ||
t.end() | ||
@@ -62,6 +44,3 @@ }) | ||
res.on('end', function () { | ||
if (skipVerification) | ||
t.skip('binary data not preserved on IE <= 8') | ||
else | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
t.end() | ||
@@ -68,0 +47,0 @@ }) |
@@ -8,8 +8,2 @@ var Buffer = require('buffer').Buffer | ||
var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() | ||
var browserName = browser.name | ||
var browserVersion = browser.major | ||
// Binary data gets corrupted in IE8 or below | ||
var skipVerification = (browserName === 'IE' && browserVersion <= 8) | ||
var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png') | ||
@@ -22,6 +16,3 @@ | ||
res.on('end', function () { | ||
if (skipVerification) | ||
t.skip('binary data not preserved on IE <= 8') | ||
else | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
t.end() | ||
@@ -28,0 +19,0 @@ }) |
@@ -8,11 +8,2 @@ var Buffer = require('buffer').Buffer | ||
var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() | ||
var browserName = browser.name | ||
var browserVersion = browser.major | ||
// Binary request bodies don't work in a bunch of browsers | ||
var skipVerification = ((browserName === 'IE' && browserVersion <= 10) || | ||
(browserName === 'Safari' && browserVersion <= 5) || | ||
(browserName === 'WebKit' && browserVersion <= 534) || // Old mobile safari | ||
(browserName === 'Android Browser' && browserVersion <= 4)) | ||
var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png') | ||
@@ -28,6 +19,3 @@ | ||
res.on('end', function () { | ||
if (skipVerification) | ||
t.skip('binary data not preserved on this browser') | ||
else | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match') | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'echoed contents match') | ||
t.end() | ||
@@ -34,0 +22,0 @@ }) |
@@ -31,6 +31,3 @@ var Buffer = require('buffer').Buffer | ||
res.on('end', function () { | ||
if (skipStreamingCheck) | ||
t.skip('streaming not available on IE <= 8') | ||
else | ||
t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts') | ||
t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts') | ||
t.ok(reference.equals(Buffer.concat(buffers)), 'contents match') | ||
@@ -37,0 +34,0 @@ t.end() |
@@ -18,3 +18,2 @@ var Buffer = require('buffer').Buffer | ||
((browserName === 'Safari' || browserName === 'Mobile Safari') && browserVersion <= 8) || | ||
(browserName === 'WebKit') || // Old mobile safari | ||
(browserName === 'Android Browser' && browserVersion <= 4)) | ||
@@ -21,0 +20,0 @@ |
@@ -7,16 +7,6 @@ var fs = require('fs') | ||
var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() | ||
var browserName = browser.name | ||
var browserVersion = browser.major | ||
// Skip browsers with poor or nonexistant WebWorker support | ||
var skip = ((browserName === 'IE' && browserVersion <= 10) || | ||
(browserName === 'Safari' && browserVersion <= 5) || | ||
(browserName === 'WebKit' && browserVersion <= 534) || // Old mobile safari | ||
(browserName === 'Android Browser' && browserVersion <= 4)) | ||
var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png') | ||
test('binary download in WebWorker', { | ||
skip: skip | ||
}, function (t) { | ||
// Temporarily disabled due to https://github.com/browserify/webworkify/issues/41 | ||
test.skip('binary download in WebWorker', function (t) { | ||
// We have to use a global url, since webworkify puts the worker in a Blob, | ||
@@ -23,0 +13,0 @@ // which doesn't have a proper location |
Sorry, the diff of this file is not supported yet
4
82284
31
1315
137
+ Addedreadable-stream@3.6.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedstring_decoder@1.3.0(transitive)
- Removedto-arraybuffer@^1.0.0
- Removedcore-util-is@1.0.3(transitive)
- Removedisarray@1.0.0(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedto-arraybuffer@1.0.1(transitive)
Updatedreadable-stream@^3.0.6