Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 2.5.0 to 2.6.0

test/browser/timeout.js

22

lib/capability.js

@@ -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

@@ -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 @@ }

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

read()
}).catch(function(err) {
self.emit('error', err)
})

@@ -58,0 +60,0 @@ }

{
"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",

@@ -97,2 +97,4 @@ # stream-http [![Build Status](https://travis-ci.org/jhiesey/stream-http.svg?branch=master)](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__';

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