diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/stream-http | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) | |
download | wallet-core-bbff7403fbf46f9ad92240ac213df8d30ef31b64.tar.xz |
update packages
Diffstat (limited to 'node_modules/stream-http')
-rw-r--r-- | node_modules/stream-http/.npmignore | 5 | ||||
-rw-r--r-- | node_modules/stream-http/.travis.yml | 6 | ||||
-rw-r--r-- | node_modules/stream-http/.zuul.yml | 22 | ||||
-rw-r--r-- | node_modules/stream-http/README.md | 14 | ||||
-rw-r--r-- | node_modules/stream-http/index.js | 6 | ||||
-rw-r--r-- | node_modules/stream-http/lib/capability.js | 4 | ||||
-rw-r--r-- | node_modules/stream-http/lib/request.js | 47 | ||||
-rw-r--r-- | node_modules/stream-http/lib/response.js | 56 | ||||
-rw-r--r-- | node_modules/stream-http/package.json | 22 | ||||
-rw-r--r-- | node_modules/stream-http/test/browser/binary-streaming.js | 4 | ||||
-rw-r--r-- | node_modules/stream-http/test/browser/post-binary.js | 3 | ||||
-rw-r--r-- | node_modules/stream-http/test/browser/text-streaming.js | 4 | ||||
-rw-r--r-- | node_modules/stream-http/test/browser/text.js | 3 | ||||
-rw-r--r-- | node_modules/stream-http/test/browser/timeout.js.disabled | 33 | ||||
-rw-r--r-- | node_modules/stream-http/test/browser/webworker.js | 3 | ||||
-rw-r--r-- | node_modules/stream-http/test/node/http-browserify.js | 16 | ||||
-rw-r--r-- | node_modules/stream-http/test/server/index.js | 2 |
17 files changed, 144 insertions, 106 deletions
diff --git a/node_modules/stream-http/.npmignore b/node_modules/stream-http/.npmignore deleted file mode 100644 index 807464b69..000000000 --- a/node_modules/stream-http/.npmignore +++ /dev/null @@ -1,5 +0,0 @@ -.DS_Store -bundle.js -node_modules -npm-debug.log -.zuulrc diff --git a/node_modules/stream-http/.travis.yml b/node_modules/stream-http/.travis.yml index 943e6b8fc..6ebc1ac29 100644 --- a/node_modules/stream-http/.travis.yml +++ b/node_modules/stream-http/.travis.yml @@ -1,3 +1,7 @@ language: node_js node_js: - - "6.4"
\ No newline at end of file + - "node" +addons: + sauce_connect: true + hosts: + - airtap.local
\ No newline at end of file diff --git a/node_modules/stream-http/.zuul.yml b/node_modules/stream-http/.zuul.yml deleted file mode 100644 index 4cb3cb985..000000000 --- a/node_modules/stream-http/.zuul.yml +++ /dev/null @@ -1,22 +0,0 @@ -ui: tape -browsers: - - name: chrome - version: 39..latest - - name: firefox - version: 34..latest - - name: safari - version: 5..latest - - name: microsoftedge - version: 13..latest - - name: ie - version: 9..latest - - name: opera - version: 11..latest - - name: iphone - version: '8.1..latest' - - name: android - version: '4.4..latest' -server: ./test/server/index.js -scripts: - - "/ie8-polyfill.js" - - "/test-polyfill.js" diff --git a/node_modules/stream-http/README.md b/node_modules/stream-http/README.md index 16e666512..94b6a50ca 100644 --- a/node_modules/stream-http/README.md +++ b/node_modules/stream-http/README.md @@ -13,6 +13,10 @@ This is heavily inspired by, and intended to replace, [http-browserify](https:// In accordance with its name, `stream-http` tries to provide data to its caller before the request has completed whenever possible. +Backpressure, allowing the browser to only pull data from the server as fast as it is +consumed, is supported in: +* Chrome >= 58 (using `fetch` and `WritableStream`) + The following browsers support true streaming, where only a small amount of the request has to be held in memory at once: * Chrome >= 43 (using the `fetch` API) @@ -80,6 +84,12 @@ capability. Preserves the correctness of binary data and the 'content-type' resp * 'prefer-fast': Deprecated; now a synonym for 'default', which has the same performance characteristics as this mode did in versions before 1.5. +* `options.requestTimeout` allows setting a timeout in millisecionds for XHR and fetch (if +supported by the browser). This is a limit on how long the entire process takes from +beginning to end. Note that this is not the same as the node `setTimeout` functions, +which apply to pauses in data transfer over the underlying socket, or the node `timeout` +option, which applies to opening the connection. + ### Features missing compared to Node * `http.Agent` is only a stub @@ -94,8 +104,8 @@ the server. * `message.trailers` and `message.rawTrailers` will remain empty. * Redirects are followed silently by the browser, so it isn't possible to access the 301/302 redirect pages. -* The `timeout` options in the `request` method is non-operational in Safari <= 5 and -Opera <= 12. +* The `timeout` event/option and `setTimeout` functions, which operate on the underlying +socket, are not available. However, see `options.requestTimeout` above. ## Example diff --git a/node_modules/stream-http/index.js b/node_modules/stream-http/index.js index 829290c43..84bfe5118 100644 --- a/node_modules/stream-http/index.js +++ b/node_modules/stream-http/index.js @@ -1,4 +1,5 @@ var ClientRequest = require('./lib/request') +var response = require('./lib/response') var extend = require('xtend') var statusCodes = require('builtin-status-codes') var url = require('url') @@ -44,9 +45,14 @@ http.get = function get (opts, cb) { return req } +http.ClientRequest = ClientRequest +http.IncomingMessage = response.IncomingMessage + http.Agent = function () {} http.Agent.defaultMaxSockets = 4 +http.globalAgent = new http.Agent() + http.STATUS_CODES = statusCodes http.METHODS = [ diff --git a/node_modules/stream-http/lib/capability.js b/node_modules/stream-http/lib/capability.js index 00dfe7696..3a17334e6 100644 --- a/node_modules/stream-http/lib/capability.js +++ b/node_modules/stream-http/lib/capability.js @@ -1,5 +1,9 @@ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream) +exports.writableStream = isFunction(global.WritableStream) + +exports.abortController = isFunction(global.AbortController) + exports.blobConstructor = false try { new Blob([new ArrayBuffer(1)]) diff --git a/node_modules/stream-http/lib/request.js b/node_modules/stream-http/lib/request.js index 36ad12db9..4f097dfa3 100644 --- a/node_modules/stream-http/lib/request.js +++ b/node_modules/stream-http/lib/request.js @@ -38,9 +38,8 @@ var ClientRequest = module.exports = function (opts) { var preferBinary var useFetch = true - if (opts.mode === 'disable-fetch' || 'timeout' in opts) { - // If the use of XHR should be preferred and includes preserving the 'content-type' header. - // Force XHR to be used since the Fetch API does not yet support timeouts. + if (opts.mode === 'disable-fetch' || ('requestTimeout' in opts && !capability.abortController)) { + // If the use of XHR should be preferred. Not typically needed. useFetch = false preferBinary = true } else if (opts.mode === 'prefer-streaming') { @@ -57,6 +56,7 @@ var ClientRequest = module.exports = function (opts) { throw new Error('Invalid value for opts.mode') } self._mode = decideMode(preferBinary, useFetch) + self._fetchTimer = null self.on('finish', function () { self._onFinish() @@ -102,7 +102,9 @@ ClientRequest.prototype._onFinish = function () { var headersObj = self._headers var body = null if (opts.method !== 'GET' && opts.method !== 'HEAD') { - if (capability.blobConstructor) { + 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) }), { @@ -129,17 +131,36 @@ ClientRequest.prototype._onFinish = function () { }) if (self._mode === 'fetch') { + var signal = null + var fetchTimer = null + if (capability.abortController) { + var controller = new AbortController() + signal = controller.signal + self._fetchAbortController = controller + + if ('requestTimeout' in opts && opts.requestTimeout !== 0) { + self._fetchTimer = global.setTimeout(function () { + self.emit('requestTimeout') + if (self._fetchAbortController) + self._fetchAbortController.abort() + }, opts.requestTimeout) + } + } + global.fetch(self._opts.url, { method: self._opts.method, headers: headersList, body: body || undefined, mode: 'cors', - credentials: opts.withCredentials ? 'include' : 'same-origin' + credentials: opts.withCredentials ? 'include' : 'same-origin', + signal: signal }).then(function (response) { self._fetchResponse = response self._connect() }, function (reason) { - self.emit('error', reason) + global.clearTimeout(self._fetchTimer) + if (!self._destroyed) + self.emit('error', reason) }) } else { var xhr = self._xhr = new global.XMLHttpRequest() @@ -162,10 +183,10 @@ ClientRequest.prototype._onFinish = function () { if (self._mode === 'text' && 'overrideMimeType' in xhr) xhr.overrideMimeType('text/plain; charset=x-user-defined') - if ('timeout' in opts) { - xhr.timeout = opts.timeout + if ('requestTimeout' in opts) { + xhr.timeout = opts.requestTimeout xhr.ontimeout = function () { - self.emit('timeout') + self.emit('requestTimeout') } } @@ -239,7 +260,7 @@ ClientRequest.prototype._connect = function () { if (self._destroyed) return - self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode) + self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._fetchTimer) self._response.on('error', function(err) { self.emit('error', err) }) @@ -257,12 +278,13 @@ ClientRequest.prototype._write = function (chunk, encoding, cb) { ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () { var self = this self._destroyed = true + global.clearTimeout(self._fetchTimer) if (self._response) self._response._destroyed = true if (self._xhr) self._xhr.abort() - // Currently, there isn't a way to truly abort a fetch. - // If you like bikeshedding, see https://github.com/whatwg/fetch/issues/27 + else if (self._fetchAbortController) + self._fetchAbortController.abort() } ClientRequest.prototype.end = function (data, encoding, cb) { @@ -301,6 +323,5 @@ var unsafeHeaders = [ 'trailer', 'transfer-encoding', 'upgrade', - 'user-agent', 'via' ] diff --git a/node_modules/stream-http/lib/response.js b/node_modules/stream-http/lib/response.js index e5d057d24..17d1fb716 100644 --- a/node_modules/stream-http/lib/response.js +++ b/node_modules/stream-http/lib/response.js @@ -10,7 +10,7 @@ var rStates = exports.readyStates = { DONE: 4 } -var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) { +var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, fetchTimer) { var self = this stream.Readable.call(self) @@ -35,30 +35,64 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) { self.statusCode = response.status self.statusMessage = response.statusText - response.headers.forEach(function(header, key){ + response.headers.forEach(function (header, key){ self.headers[key.toLowerCase()] = header self.rawHeaders.push(key, header) }) + if (capability.writableStream) { + var writable = new WritableStream({ + write: function (chunk) { + return new Promise(function (resolve, reject) { + if (self._destroyed) { + reject() + } else if(self.push(new Buffer(chunk))) { + resolve() + } else { + self._resumeFetch = resolve + } + }) + }, + close: function () { + global.clearTimeout(fetchTimer) + if (!self._destroyed) + self.push(null) + }, + abort: function (err) { + if (!self._destroyed) + self.emit('error', err) + } + }) - // TODO: this doesn't respect backpressure. Once WritableStream is available, this can be fixed + try { + response.body.pipeTo(writable).catch(function (err) { + global.clearTimeout(fetchTimer) + if (!self._destroyed) + self.emit('error', err) + }) + return + } catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this + } + // fallback for when writableStream or pipeTo aren't available var reader = response.body.getReader() function read () { reader.read().then(function (result) { if (self._destroyed) return if (result.done) { + global.clearTimeout(fetchTimer) self.push(null) return } self.push(new Buffer(result.value)) read() - }).catch(function(err) { - self.emit('error', err) + }).catch(function (err) { + global.clearTimeout(fetchTimer) + if (!self._destroyed) + self.emit('error', err) }) } read() - } else { self._xhr = xhr self._pos = 0 @@ -102,7 +136,15 @@ var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode) { inherits(IncomingMessage, stream.Readable) -IncomingMessage.prototype._read = function () {} +IncomingMessage.prototype._read = function () { + var self = this + + var resolve = self._resumeFetch + if (resolve) { + self._resumeFetch = null + resolve() + } +} IncomingMessage.prototype._onXHRProgress = function () { var self = this diff --git a/node_modules/stream-http/package.json b/node_modules/stream-http/package.json index a664bb4ba..1e1affa79 100644 --- a/node_modules/stream-http/package.json +++ b/node_modules/stream-http/package.json @@ -1,6 +1,6 @@ { "name": "stream-http", - "version": "2.7.2", + "version": "2.8.3", "description": "Streaming http in the browser", "main": "index.js", "repository": { @@ -10,8 +10,8 @@ "scripts": { "test": "npm run test-node && ([ -n \"${TRAVIS_PULL_REQUEST}\" -a \"${TRAVIS_PULL_REQUEST}\" != 'false' ] || npm run test-browser)", "test-node": "tape test/node/*.js", - "test-browser": "zuul --no-coverage -- test/browser/*.js", - "test-browser-local": "zuul --local 8080 --no-coverage -- test/browser/*.js" + "test-browser": "airtap --loopback airtap.local -- test/browser/*.js", + "test-browser-local": "airtap --no-instrument --local 8080 -- test/browser/*.js" }, "author": "John Hiesey", "license": "MIT", @@ -29,18 +29,18 @@ "dependencies": { "builtin-status-codes": "^3.0.0", "inherits": "^2.0.1", - "readable-stream": "^2.2.6", + "readable-stream": "^2.3.6", "to-arraybuffer": "^1.0.0", "xtend": "^4.0.0" }, "devDependencies": { - "basic-auth": "^1.0.3", - "brfs": "^1.4.0", + "airtap": "^0.0.5", + "basic-auth": "^2.0.0", + "brfs": "^1.6.1", "cookie-parser": "^1.4.3", - "express": "^4.15.2", - "tape": "^4.0.0", - "ua-parser-js": "^0.7.7", - "webworkify": "^1.0.2", - "zuul": "^3.10.3" + "express": "^4.16.3", + "tape": "^4.9.0", + "ua-parser-js": "^0.7.18", + "webworkify": "^1.5.0" } } diff --git a/node_modules/stream-http/test/browser/binary-streaming.js b/node_modules/stream-http/test/browser/binary-streaming.js index 4d2d63e00..d1221dfe2 100644 --- a/node_modules/stream-http/test/browser/binary-streaming.js +++ b/node_modules/stream-http/test/browser/binary-streaming.js @@ -8,8 +8,8 @@ var http = require('../..') 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 or in Opera -var skipStreamingCheck = (browserName === 'Opera' || (browserName === 'IE' && browserVersion <= 10)) +// 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) diff --git a/node_modules/stream-http/test/browser/post-binary.js b/node_modules/stream-http/test/browser/post-binary.js index 31b465caa..52f3d7ea6 100644 --- a/node_modules/stream-http/test/browser/post-binary.js +++ b/node_modules/stream-http/test/browser/post-binary.js @@ -9,8 +9,7 @@ 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 === 'Opera' && browserVersion <= 11) || - (browserName === 'IE' && browserVersion <= 10) || +var skipVerification = ((browserName === 'IE' && browserVersion <= 10) || (browserName === 'Safari' && browserVersion <= 5) || (browserName === 'WebKit' && browserVersion <= 534) || // Old mobile safari (browserName === 'Android Browser' && browserVersion <= 4)) diff --git a/node_modules/stream-http/test/browser/text-streaming.js b/node_modules/stream-http/test/browser/text-streaming.js index 812ef1457..21693afd4 100644 --- a/node_modules/stream-http/test/browser/text-streaming.js +++ b/node_modules/stream-http/test/browser/text-streaming.js @@ -8,8 +8,8 @@ var http = require('../..') var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() var browserName = browser.name var browserVersion = browser.major -// Streaming doesn't work in IE9 or below or in Opera -var skipStreamingCheck = (browserName === 'Opera' || (browserName === 'IE' && browserVersion <= 9)) +// Streaming doesn't work in IE9 or below +var skipStreamingCheck = (browserName === 'IE' && browserVersion <= 9) var COPIES = 1000 var MIN_PIECES = 5 diff --git a/node_modules/stream-http/test/browser/text.js b/node_modules/stream-http/test/browser/text.js index 6cc1c8148..568380ce6 100644 --- a/node_modules/stream-http/test/browser/text.js +++ b/node_modules/stream-http/test/browser/text.js @@ -10,8 +10,7 @@ var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() var browserName = browser.name var browserVersion = browser.major // Response urls don't work on many browsers -var skipResponseUrl = ((browserName === 'Opera') || - (browserName === 'IE') || +var skipResponseUrl = ((browserName === 'IE') || (browserName === 'Edge') || (browserName === 'Chrome' && browserVersion <= 36) || (browserName === 'Firefox' && browserVersion <= 31) || diff --git a/node_modules/stream-http/test/browser/timeout.js.disabled b/node_modules/stream-http/test/browser/timeout.js.disabled deleted file mode 100644 index a49efdfb3..000000000 --- a/node_modules/stream-http/test/browser/timeout.js.disabled +++ /dev/null @@ -1,33 +0,0 @@ -var Buffer = require('buffer').Buffer -var fs = require('fs') -var test = require('tape') -var UAParser = require('ua-parser-js') -var url = require('url') - -var http = require('../..') - -var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser() -var browserName = browser.name -var browserVersion = browser.major - -var skipTimeout = ((browserName === 'Opera' && browserVersion <= 12) || - (browserName === 'Safari' && browserVersion <= 5)) - - -test('emits timeout events', function (t) { - if (skipTimeout) { - return t.skip('Browser does not support setting timeouts') - } - - var req = http.request({ - path: '/basic.txt', - timeout: 1 - }) - - req.on('timeout', function () { - t.pass('timeout caught') - t.end() // the test will timeout if this does not happen - }) - - req.end() -}) diff --git a/node_modules/stream-http/test/browser/webworker.js b/node_modules/stream-http/test/browser/webworker.js index b1df06471..063706cf0 100644 --- a/node_modules/stream-http/test/browser/webworker.js +++ b/node_modules/stream-http/test/browser/webworker.js @@ -8,8 +8,7 @@ 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 === 'Opera' && browserVersion <= 12) || - (browserName === 'IE' && browserVersion <= 10) || +var skip = ((browserName === 'IE' && browserVersion <= 10) || (browserName === 'Safari' && browserVersion <= 5) || (browserName === 'WebKit' && browserVersion <= 534) || // Old mobile safari (browserName === 'Android Browser' && browserVersion <= 4)) diff --git a/node_modules/stream-http/test/node/http-browserify.js b/node_modules/stream-http/test/node/http-browserify.js index fda851232..42a718f08 100644 --- a/node_modules/stream-http/test/node/http-browserify.js +++ b/node_modules/stream-http/test/node/http-browserify.js @@ -1,4 +1,4 @@ -// These tests are teken from http-browserify to ensure compatibility with +// These tests are taken from http-browserify to ensure compatibility with // that module var test = require('tape') var url = require('url') @@ -17,6 +17,20 @@ var moduleName = require.resolve('../../') delete require.cache[moduleName] var http = require('../../') +test('Make sure http object has correct properties', function (t) { + t.ok(http.Agent, 'Agent defined') + t.ok(http.ClientRequest, 'ClientRequest defined') + t.ok(http.ClientRequest.prototype, 'ClientRequest.prototype defined') + t.ok(http.IncomingMessage, 'IncomingMessage defined') + t.ok(http.IncomingMessage.prototype, 'IncomingMessage.prototype defined') + t.ok(http.METHODS, 'METHODS defined') + t.ok(http.STATUS_CODES, 'STATUS_CODES defined') + t.ok(http.get, 'get defined') + t.ok(http.globalAgent, 'globalAgent defined') + t.ok(http.request, 'request defined') + t.end() +}) + test('Test simple url string', function(t) { var testUrl = { path: '/api/foo' } var request = http.get(testUrl, noop) diff --git a/node_modules/stream-http/test/server/index.js b/node_modules/stream-http/test/server/index.js index f9f45de04..0a74aed85 100644 --- a/node_modules/stream-http/test/server/index.js +++ b/node_modules/stream-http/test/server/index.js @@ -132,6 +132,6 @@ app.use(function (req, res, next) { app.use(express.static(path.join(__dirname, 'static'))) -var port = parseInt(process.env.ZUUL_PORT) || 8199 +var port = parseInt(process.env.AIRTAP_PORT) || 8199 console.log('Test server listening on port', port) server.listen(port) |