Socket
Socket
Sign inDemoInstall

stream-http

Package Overview
Dependencies
Maintainers
1
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 1.5.0 to 1.6.0

22

index.js

@@ -14,15 +14,15 @@ var ClientRequest = require('./lib/request')

// Split opts.host into its components
var hostHostname = opts.host ? opts.host.split(':')[0] : null
var hostPort = opts.host ? parseInt(opts.host.split(':')[1], 10) : null
var protocol = opts.protocol || ''
var host = opts.hostname || opts.host
var port = opts.port
var path = opts.path || '/'
opts.method = opts.method || 'GET'
// Necessary for IPv6 addresses
if (host && host.indexOf(':') !== -1)
host = '[' + host + ']'
// This may be a relative url. The browser should always be able to interpret it correctly.
opts.url = (host ? (protocol + '//' + host) : '') + (port ? ':' + port : '') + path
opts.method = (opts.method || 'GET').toUpperCase()
opts.headers = opts.headers || {}
opts.path = opts.path || '/'
opts.protocol = opts.protocol || window.location.protocol
// If the hostname is provided, use the default port for the protocol. If
// the url is instead relative, use window.location.port
var defaultPort = (opts.hostname || hostHostname) ? (opts.protocol === 'https:' ? 443 : 80) : window.location.port
opts.hostname = opts.hostname || hostHostname || window.location.hostname
opts.port = opts.port || hostPort || defaultPort

@@ -29,0 +29,0 @@ // Also valid opts.auth, opts.mode

@@ -34,3 +34,2 @@ // var Base64 = require('Base64')

self._opts = opts
self._url = opts.protocol + '//' + opts.hostname + ':' + opts.port + opts.path
self._body = []

@@ -119,3 +118,3 @@ self._headers = {}

window.fetch(self._url, {
window.fetch(self._opts.url, {
method: self._opts.method,

@@ -135,3 +134,3 @@ headers: headers,

try {
xhr.open(self._opts.method, self._url, true)
xhr.open(self._opts.method, self._opts.url, true)
} catch (err) {

@@ -138,0 +137,0 @@ process.nextTick(function () {

{
"name": "stream-http",
"version": "1.5.0",
"version": "1.6.0",
"description": "Streaming http in the browser",

@@ -26,7 +26,7 @@ "main": "index.js",

"dependencies": {
"builtin-status-codes": "~1.0.0",
"builtin-status-codes": "^1.0.0",
"foreach": "^2.0.5",
"indexof": "0.0.1",
"inherits": "^2.0.1",
"object-keys": "1.0.4",
"object-keys": "^1.0.4",
"xtend": "^4.0.0"

@@ -33,0 +33,0 @@ },

@@ -45,3 +45,3 @@ # stream-http [![Build Status](https://travis-ci.org/jhiesey/stream-http.svg?branch=master)](https://travis-ci.org/jhiesey/stream-http)

* The `options.withCredentials` boolean flag, used to indicate if the browser should send
cookies or authentication information with a CORS request. Default true.
cookies or authentication information with a CORS request. Default false.

@@ -48,0 +48,0 @@ This module has to make some tradeoffs to support binary data and/or streaming. Generally,

// These tests are teken from http-browserify to ensure compatibility with
// that module
var test = require('tape')
var url = require('url')
global.window = {}
window.location = {
hostname: 'localhost',
port: 8081,
protocol: 'http:'
}
var location = 'http://localhost:8081/foo/123'
var noop = function() {}
global.window = {}
window.XMLHttpRequest = function() {

@@ -24,6 +21,7 @@ this.open = noop

test('Test simple url string', function(t) {
var url = { path: '/api/foo' }
var request = http.get(url, noop)
var testUrl = { path: '/api/foo' }
var request = http.get(testUrl, noop)
t.equal( request._url, 'http://localhost:8081/api/foo', 'Url should be correct')
var resolved = url.resolve(location, request._opts.url)
t.equal(resolved, 'http://localhost:8081/api/foo', 'Url should be correct')
t.end()

@@ -34,3 +32,3 @@

test('Test full url object', function(t) {
var url = {
var testUrl = {
host: "localhost:8081",

@@ -49,7 +47,7 @@ hostname: "localhost",

var request = http.get(url, noop)
var request = http.get(testUrl, noop)
t.equal( request._url, 'http://localhost:8081/api/foo?bar=baz', 'Url should be correct')
var resolved = url.resolve(location, request._opts.url)
t.equal(resolved, 'http://localhost:8081/api/foo?bar=baz', 'Url should be correct')
t.end()
})

@@ -67,14 +65,14 @@

t.equal( request._url, 'foo://localhost:3000/bar', 'Url should be correct')
var resolved = url.resolve(location, request._opts.url)
t.equal(resolved, 'foo://localhost:3000/bar', 'Url should be correct')
t.end()
})
test('Test string as parameters', function(t) {
var url = '/api/foo'
var request = http.get(url, noop)
var testUrl = '/api/foo'
var request = http.get(testUrl, noop)
t.equal( request._url, 'http://localhost:8081/api/foo', 'Url should be correct')
var resolved = url.resolve(location, request._opts.url)
t.equal(resolved, 'http://localhost:8081/api/foo', 'Url should be correct')
t.end()
})

@@ -86,9 +84,9 @@

var request = http.get({ url: url, withCredentials: false }, noop)
t.equal( request._xhr.withCredentials, false, 'xhr.withCredentials should be false')
t.equal(request._xhr.withCredentials, false, 'xhr.withCredentials should be false')
var request = http.get({ url: url, withCredentials: true }, noop)
t.equal( request._xhr.withCredentials, true, 'xhr.withCredentials should be true')
t.equal(request._xhr.withCredentials, true, 'xhr.withCredentials should be true')
var request = http.get({ url: url }, noop)
t.equal( request._xhr.withCredentials, false, 'xhr.withCredentials should be false')
t.equal(request._xhr.withCredentials, false, 'xhr.withCredentials should be false')

@@ -98,2 +96,20 @@ t.end()

test('Test ipv6 address', function(t) {
var testUrl = 'http://[::1]:80/foo'
var request = http.get(testUrl, noop)
var resolved = url.resolve(location, request._opts.url)
t.equal(resolved, 'http://[::1]:80/foo', 'Url should be correct')
t.end()
})
test('Test relative path in url', function(t) {
var params = { path: './bar' }
var request = http.get(params, noop)
var resolved = url.resolve(location, request._opts.url)
t.equal(resolved, 'http://localhost:8081/foo/bar', 'Url should be correct')
t.end()
})
test('Cleanup', function (t) {

@@ -100,0 +116,0 @@ delete global.window

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