Socket
Socket
Sign inDemoInstall

stream-http

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-http - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

50

lib/request.js

@@ -57,2 +57,4 @@ var capability = require('./capability')

self._fetchTimer = null
self._socketTimeout = null
self._socketTimer = null

@@ -100,2 +102,6 @@ self.on('finish', function () {

if ('timeout' in opts && opts.timeout !== 0) {
self.setTimeout(opts.timeout)
}
var headersObj = self._headers

@@ -148,5 +154,6 @@ var body = null

self._fetchResponse = response
self._resetTimers(false)
self._connect()
}, function (reason) {
global.clearTimeout(self._fetchTimer)
self._resetTimers(true)
if (!self._destroyed)

@@ -207,2 +214,3 @@ self.emit('error', reason)

return
self._resetTimers(true)
self.emit('error', new Error('XHR error'))

@@ -239,2 +247,4 @@ }

self._resetTimers(false)
if (!statusValid(self._xhr) || self._destroyed)

@@ -246,3 +256,3 @@ return

self._response._onXHRProgress()
self._response._onXHRProgress(self._resetTimers.bind(self))
}

@@ -256,3 +266,3 @@

self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._fetchTimer)
self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self))
self._response.on('error', function(err) {

@@ -272,6 +282,22 @@ self.emit('error', err)

ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function () {
ClientRequest.prototype._resetTimers = function (done) {
var self = this
global.clearTimeout(self._socketTimer)
self._socketTimer = null
if (done) {
global.clearTimeout(self._fetchTimer)
self._fetchTimer = null
} else if (self._socketTimeout) {
self._socketTimer = global.setTimeout(function () {
self.emit('timeout')
}, self._socketTimeout)
}
}
ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) {
var self = this
self._destroyed = true
global.clearTimeout(self._fetchTimer)
self._resetTimers(true)
if (self._response)

@@ -283,2 +309,5 @@ self._response._destroyed = true

self._fetchAbortController.abort()
if (err)
self.emit('error', err)
}

@@ -296,4 +325,13 @@

ClientRequest.prototype.setTimeout = function (timeout, cb) {
var self = this
if (cb)
self.once('timeout', cb)
self._socketTimeout = timeout
self._resetTimers(false)
}
ClientRequest.prototype.flushHeaders = function () {}
ClientRequest.prototype.setTimeout = function () {}
ClientRequest.prototype.setNoDelay = function () {}

@@ -300,0 +338,0 @@ ClientRequest.prototype.setSocketKeepAlive = function () {}

16

lib/response.js

@@ -13,3 +13,3 @@ var capability = require('./capability')

var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, fetchTimer) {
var IncomingMessage = exports.IncomingMessage = function (xhr, response, mode, resetTimers) {
var self = this

@@ -47,2 +47,3 @@ stream.Readable.call(self)

write: function (chunk) {
resetTimers(false)
return new Promise(function (resolve, reject) {

@@ -59,3 +60,3 @@ if (self._destroyed) {

close: function () {
global.clearTimeout(fetchTimer)
resetTimers(true)
if (!self._destroyed)

@@ -65,2 +66,3 @@ self.push(null)

abort: function (err) {
resetTimers(true)
if (!self._destroyed)

@@ -73,3 +75,3 @@ self.emit('error', err)

response.body.pipeTo(writable).catch(function (err) {
global.clearTimeout(fetchTimer)
resetTimers(true)
if (!self._destroyed)

@@ -87,4 +89,4 @@ self.emit('error', err)

return
resetTimers(result.done)
if (result.done) {
global.clearTimeout(fetchTimer)
self.push(null)

@@ -96,3 +98,3 @@ return

}).catch(function (err) {
global.clearTimeout(fetchTimer)
resetTimers(true)
if (!self._destroyed)

@@ -156,3 +158,3 @@ self.emit('error', err)

IncomingMessage.prototype._onXHRProgress = function () {
IncomingMessage.prototype._onXHRProgress = function (resetTimers) {
var self = this

@@ -204,2 +206,3 @@

reader.onload = function () {
resetTimers(true)
self.push(null)

@@ -214,4 +217,5 @@ }

if (self._xhr.readyState === rStates.DONE && self._mode !== 'ms-stream') {
resetTimers(true)
self.push(null)
}
}
{
"name": "stream-http",
"version": "3.1.1",
"version": "3.2.0",
"description": "Streaming http in the browser",

@@ -13,4 +13,4 @@ "main": "index.js",

"test-node": "tape test/node/*.js",
"test-browser": "airtap --loopback airtap.local -- test/browser/*.js",
"test-browser-local": "airtap --no-instrument --local 8080 -- test/browser/*.js"
"test-browser": "airtap --concurrency 1 -- test/browser/*.js",
"test-browser-local": "airtap --preset local -- test/browser/*.js"
},

@@ -37,3 +37,5 @@ "author": "John Hiesey",

"devDependencies": {
"airtap": "^3.0.0",
"airtap": "^4.0.3",
"airtap-manual": "^1.0.0",
"airtap-sauce": "^1.1.0",
"basic-auth": "^2.0.1",

@@ -43,6 +45,6 @@ "brfs": "^2.0.2",

"express": "^4.17.1",
"tape": "^5.0.0",
"ua-parser-js": "^0.7.21",
"tape": "^5.2.2",
"ua-parser-js": "^0.7.28",
"webworkify": "^1.5.0"
}
}
# stream-http [![Build Status](https://travis-ci.org/jhiesey/stream-http.svg?branch=master)](https://travis-ci.org/jhiesey/stream-http)
[![Sauce Test Status](https://saucelabs.com/browser-matrix/stream-http.svg)](https://saucelabs.com/u/stream-http)
[![Sauce Test Status](https://app.saucelabs.com/browser-matrix/stream-http.svg)](https://app.saucelabs.com/u/stream-http)

@@ -87,3 +87,3 @@ This module is an implementation of Node's native `http` module for the browser.

* The 'socket', 'connect', 'upgrade', and 'continue' events on `http.ClientRequest`.
* Any operations, including `request.setTimeout`, that operate directly on the underlying
* Any operations, other than `request.setTimeout`, that operate directly on the underlying
socket.

@@ -98,4 +98,2 @@ * Any options that are disallowed for security reasons. This includes setting or getting

redirect pages.
* The `timeout` event/option and `setTimeout` functions, which operate on the underlying
socket, are not available. However, see `options.requestTimeout` above.

@@ -102,0 +100,0 @@ ## Example

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc