stream-http
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -93,2 +93,4 @@ // var Base64 = require('Base64') | ||
if (self._destroyed) | ||
return | ||
var opts = self._opts | ||
@@ -171,2 +173,4 @@ | ||
xhr.onerror = function () { | ||
if (self._destroyed) | ||
return | ||
self.emit('error', new Error('XHR error')) | ||
@@ -201,3 +205,3 @@ } | ||
if (!statusValid(self._xhr) || self._failed) | ||
if (!statusValid(self._xhr) || self._destroyed) | ||
return | ||
@@ -214,2 +218,5 @@ | ||
if (self._destroyed) | ||
return | ||
self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode) | ||
@@ -226,6 +233,11 @@ self.emit('response', self._response) | ||
ClientRequest.prototype.abort = function () { | ||
ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () { | ||
var self = this | ||
self._destroyed = true | ||
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 | ||
} | ||
@@ -274,2 +286,2 @@ | ||
'via' | ||
]; | ||
] |
@@ -24,2 +24,10 @@ var capability = require('./capability') | ||
// Fake the 'close' event, but only once 'end' fires | ||
self.on('end', function () { | ||
// The nextTick is necessary to prevent the 'request' module from causing an infinite loop | ||
process.nextTick(function () { | ||
self.emit('close') | ||
}) | ||
}) | ||
if (mode === 'fetch') { | ||
@@ -41,2 +49,4 @@ self._fetchResponse = response | ||
reader.read().then(function (result) { | ||
if (self._destroyed) | ||
return | ||
if (result.done) { | ||
@@ -43,0 +53,0 @@ self.push(null) |
{ | ||
"name": "stream-http", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Streaming http in the browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67446
26
933
10