stream-http
Advanced tools
| var test = require('tape') | ||
| var http = require('../..') | ||
| 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.end() // the test will timeout if this does not happen | ||
| }) | ||
| req.end() | ||
| }) |
+16
-6
@@ -9,8 +9,18 @@ exports.fetch = isFunction(global.fetch) && isFunction(global.ReadableStream) | ||
| var 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 | ||
| xhr.open('GET', global.XDomainRequest ? '/' : 'https://example.com') | ||
| // 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) { | ||
| xhr = null | ||
| } | ||
| } | ||
| function checkTypeSupport (type) { | ||
| if (!xhr) return false | ||
| try { | ||
@@ -34,9 +44,9 @@ xhr.responseType = type | ||
| checkTypeSupport('moz-chunked-arraybuffer') | ||
| exports.overrideMimeType = isFunction(xhr.overrideMimeType) | ||
| exports.overrideMimeType = xhr ? isFunction(xhr.overrideMimeType) : false | ||
| exports.vbArray = isFunction(global.VBArray) | ||
| function isFunction (value) { | ||
| return typeof value === 'function' | ||
| return typeof value === 'function' | ||
| } | ||
| xhr = null // Help gc |
+14
-2
@@ -41,4 +41,5 @@ var capability = require('./capability') | ||
| var useFetch = true | ||
| if (opts.mode === 'disable-fetch') { | ||
| // If the use of XHR should be preferred and includes preserving the 'content-type' header | ||
| 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. | ||
| useFetch = false | ||
@@ -153,2 +154,9 @@ preferBinary = true | ||
| if ('timeout' in opts) { | ||
| xhr.timeout = opts.timeout | ||
| xhr.ontimeout = function () { | ||
| self.emit('timeout') | ||
| } | ||
| } | ||
| Object.keys(headersObj).forEach(function (name) { | ||
@@ -225,2 +233,6 @@ xhr.setRequestHeader(headersObj[name].name, headersObj[name].value) | ||
| self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode) | ||
| self._response.on('error', function(err) { | ||
| self.emit('error', err) | ||
| }) | ||
| self.emit('response', self._response) | ||
@@ -227,0 +239,0 @@ } |
+2
-0
@@ -56,2 +56,4 @@ var capability = require('./capability') | ||
| read() | ||
| }).catch(function(err) { | ||
| self.emit('error', err) | ||
| }) | ||
@@ -58,0 +60,0 @@ } |
+2
-2
| { | ||
| "name": "stream-http", | ||
| "version": "2.5.0", | ||
| "version": "2.6.0", | ||
| "description": "Streaming http in the browser", | ||
@@ -30,3 +30,3 @@ "main": "index.js", | ||
| "dependencies": { | ||
| "builtin-status-codes": "^2.0.0", | ||
| "builtin-status-codes": "^3.0.0", | ||
| "inherits": "^2.0.1", | ||
@@ -33,0 +33,0 @@ "readable-stream": "^2.1.0", |
+4
-2
@@ -97,2 +97,4 @@ # stream-http [](https://travis-ci.org/jhiesey/stream-http) | ||
| redirect pages. | ||
| * The `timeout` options in the `request` method is non-operational in Safari <= 5 and | ||
| Opera <= 12. | ||
@@ -105,7 +107,7 @@ ## Example | ||
| div.innerHTML += 'GET /beep<br>'; | ||
| res.on('data', function (buf) { | ||
| div.innerHTML += buf; | ||
| }); | ||
| res.on('end', function () { | ||
@@ -112,0 +114,0 @@ div.innerHTML += '<br>__END__'; |
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
84217
1.44%32
3.23%1337
3%135
1.5%+ Added
- Removed
Updated