Socket
Socket
Sign inDemoInstall

request

Package Overview
Dependencies
57
Maintainers
4
Versions
126
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.57.0 to 2.58.0

lib/tunnel.js

6

CHANGELOG.md
## Change Log
### v2.58.0 (2015/06/16)
- [#1638](https://github.com/request/request/pull/1638) Use the `extend` module to deep extend in the defaults method (@simov)
- [#1631](https://github.com/request/request/pull/1631) Move tunnel logic into separate module (@simov)
- [#1634](https://github.com/request/request/pull/1634) Fix OAuth query transport_method (@simov)
- [#1603](https://github.com/request/request/pull/1603) Add codecov (@simov)
### v2.57.0 (2015/05/31)

@@ -4,0 +10,0 @@ - [#1615](https://github.com/request/request/pull/1615) Replace '.client' with '.socket' as the former was deprecated in 2.2.0. (@ChALkeR)

25

index.js

@@ -17,3 +17,3 @@ // Copyright 2010-2012 Mikeal Rogers

var extend = require('util')._extend
var extend = require('extend')
, cookies = require('./lib/cookies')

@@ -34,8 +34,7 @@ , helpers = require('./lib/helpers')

if (typeof options === 'object') {
params = extend({}, options)
params = extend(params, {uri: uri})
extend(params, options, {uri: uri})
} else if (typeof uri === 'string') {
params = extend({}, {uri: uri})
extend(params, {uri: uri})
} else {
params = extend({}, uri)
extend(params, uri)
}

@@ -91,13 +90,7 @@

var headerlessOptions = extend({}, options)
delete headerlessOptions.headers
params = extend(headerlessOptions, params)
var target = {}
extend(true, target, options, params)
if (options.headers) {
var headers = extend({}, options.headers)
params.headers = extend(headers, params.headers)
}
if (verb) {
params.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase())
target.method = (verb === 'del' ? 'DELETE' : verb.toUpperCase())
}

@@ -109,3 +102,3 @@

return method(params, params.callback)
return method(target, target.callback)
}

@@ -138,3 +131,3 @@ }

if (optionsArg) {
options = extend({}, optionsArg)
extend(options, optionsArg)
}

@@ -141,0 +134,0 @@ if (agentOptions) {

@@ -49,2 +49,10 @@ 'use strict'

function copy (obj) {
var o = {}
Object.keys(obj).forEach(function (i) {
o[i] = obj[i]
})
return o
}
exports.isFunction = isFunction

@@ -56,2 +64,3 @@ exports.paramsHaveRequestBody = paramsHaveRequestBody

exports.toBase64 = toBase64
exports.copy = copy
exports.defer = deferMethod()
'use strict'
var qs = require('qs')
var url = require('url')
, qs = require('qs')
, caseless = require('caseless')

@@ -132,3 +133,5 @@ , uuid = require('node-uuid')

case 'query':
self.request.path = (query ? '&' : '?') + self.concatParams(oa, '&')
var href = self.request.uri.href += (query ? '&' : '?') + self.concatParams(oa, '&')
self.request.uri = url.parse(href)
self.request.path = self.request.uri.path
break

@@ -135,0 +138,0 @@

@@ -10,3 +10,3 @@ {

],
"version": "2.57.0",
"version": "2.58.0",
"author": "Mikeal Rogers <mikeal.rogers@gmail.com>",

@@ -28,4 +28,5 @@ "repository": {

"caseless": "~0.10.0",
"extend": "~2.0.1",
"forever-agent": "~0.6.0",
"form-data": "~0.2.0",
"form-data": "~1.0.0-rc1",
"json-stringify-safe": "~5.0.0",

@@ -47,5 +48,7 @@ "mime-types": "~2.0.1",

"scripts": {
"test": "npm run lint && node node_modules/.bin/taper tests/test-*.js && npm run test-browser",
"test": "npm run lint && npm run test-ci && npm run test-browser",
"test-ci": "taper tests/test-*.js",
"test-cov": "istanbul cover tape tests/test-*.js",
"test-browser": "node tests/browser/start.js",
"lint": "node node_modules/.bin/eslint lib/ *.js tests/ && echo Lint passed."
"lint": "eslint lib/ *.js tests/ && echo Lint passed."
},

@@ -56,2 +59,3 @@ "devDependencies": {

"buffer-equal": "0.0.1",
"codecov.io": "~0.1.2",
"coveralls": "~2.11.2",

@@ -58,0 +62,0 @@ "eslint": "0.18.0",

@@ -7,2 +7,3 @@

[![Build status](https://img.shields.io/travis/request/request.svg?style=flat-square)](https://travis-ci.org/request/request)
[![Coverage](https://img.shields.io/codecov/c/github/request/request.svg?style=flat-square)](https://codecov.io/github/request/request?branch=master)
[![Coverage](https://img.shields.io/coveralls/request/request.svg?style=flat-square)](https://coveralls.io/r/request/request)

@@ -414,3 +415,3 @@ [![Dependency Status](https://img.shields.io/david/request/request.svg?style=flat-square)](https://david-dm.org/request/request)

;
request.get({url:url, oauth:oauth, json:true}, function (e, r, user) {
request.get({url:url, oauth:oauth, qs:qs, json:true}, function (e, r, user) {
console.log(user)

@@ -417,0 +418,0 @@ })

@@ -9,3 +9,2 @@ 'use strict'

, zlib = require('zlib')
, helpers = require('./lib/helpers')
, bl = require('bl')

@@ -16,3 +15,2 @@ , hawk = require('hawk')

, mime = require('mime-types')
, tunnel = require('tunnel-agent')
, stringstream = require('stringstream')

@@ -22,4 +20,4 @@ , caseless = require('caseless')

, FormData = require('form-data')
, helpers = require('./lib/helpers')
, cookies = require('./lib/cookies')
, copy = require('./lib/copy')
, getProxyFromURI = require('./lib/getProxyFromURI')

@@ -32,2 +30,3 @@ , Querystring = require('./lib/querystring').Querystring

, Redirect = require('./lib/redirect').Redirect
, Tunnel = require('./lib/tunnel').Tunnel

@@ -38,2 +37,3 @@ var safeStringify = helpers.safeStringify

, defer = helpers.defer
, copy = helpers.copy
, globalCookieJar = cookies.jar()

@@ -44,32 +44,2 @@

var defaultProxyHeaderWhiteList = [
'accept',
'accept-charset',
'accept-encoding',
'accept-language',
'accept-ranges',
'cache-control',
'content-encoding',
'content-language',
'content-length',
'content-location',
'content-md5',
'content-range',
'content-type',
'connection',
'date',
'expect',
'max-forwards',
'pragma',
'referer',
'te',
'transfer-encoding',
'user-agent',
'via'
]
var defaultProxyHeaderExclusiveList = [
'proxy-authorization'
]
function filterForNonReserved(reserved, options) {

@@ -105,99 +75,2 @@ // Filter out properties that are not reserved.

function constructProxyHost(uriObject) {
var port = uriObject.portA
, protocol = uriObject.protocol
, proxyHost = uriObject.hostname + ':'
if (port) {
proxyHost += port
} else if (protocol === 'https:') {
proxyHost += '443'
} else {
proxyHost += '80'
}
return proxyHost
}
function constructProxyHeaderWhiteList(headers, proxyHeaderWhiteList) {
var whiteList = proxyHeaderWhiteList
.reduce(function (set, header) {
set[header.toLowerCase()] = true
return set
}, {})
return Object.keys(headers)
.filter(function (header) {
return whiteList[header.toLowerCase()]
})
.reduce(function (set, header) {
set[header] = headers[header]
return set
}, {})
}
function getTunnelOption(self, options) {
// Tunnel HTTPS by default, or if a previous request in the redirect chain
// was tunneled. Allow the user to override this setting.
// If self.tunnel is already set (because this is a redirect), use the
// existing value.
if (typeof self.tunnel !== 'undefined') {
return self.tunnel
}
// If options.tunnel is set (the user specified a value), use it.
if (typeof options.tunnel !== 'undefined') {
return options.tunnel
}
// If the destination is HTTPS, tunnel.
if (self.uri.protocol === 'https:') {
return true
}
// Otherwise, leave tunnel unset, because if a later request in the redirect
// chain is HTTPS then that request (and any subsequent ones) should be
// tunneled.
return undefined
}
function constructTunnelOptions(request) {
var proxy = request.proxy
var tunnelOptions = {
proxy : {
host : proxy.hostname,
port : +proxy.port,
proxyAuth : proxy.auth,
headers : request.proxyHeaders
},
headers : request.headers,
ca : request.ca,
cert : request.cert,
key : request.key,
passphrase : request.passphrase,
pfx : request.pfx,
ciphers : request.ciphers,
rejectUnauthorized : request.rejectUnauthorized,
secureOptions : request.secureOptions,
secureProtocol : request.secureProtocol
}
return tunnelOptions
}
function constructTunnelFnName(uri, proxy) {
var uriProtocol = (uri.protocol === 'https:' ? 'https' : 'http')
var proxyProtocol = (proxy.protocol === 'https:' ? 'Https' : 'Http')
return [uriProtocol, proxyProtocol].join('Over')
}
function getTunnelFn(request) {
var uri = request.uri
var proxy = request.proxy
var tunnelFnName = constructTunnelFnName(uri, proxy)
return tunnel[tunnelFnName]
}
// Function for properly handling a connection error

@@ -272,2 +145,3 @@ function connectionErrorHandler(error) {

self._redirect = new Redirect(self)
self._tunnel = new Tunnel(self)
self.init(options)

@@ -287,33 +161,2 @@ }

Request.prototype.setupTunnel = function () {
var self = this
if (typeof self.proxy === 'string') {
self.proxy = url.parse(self.proxy)
}
if (!self.proxy || !self.tunnel) {
return false
}
// Setup Proxy Header Exclusive List and White List
self.proxyHeaderExclusiveList = self.proxyHeaderExclusiveList || []
self.proxyHeaderWhiteList = self.proxyHeaderWhiteList || defaultProxyHeaderWhiteList
var proxyHeaderExclusiveList = self.proxyHeaderExclusiveList.concat(defaultProxyHeaderExclusiveList)
var proxyHeaderWhiteList = self.proxyHeaderWhiteList.concat(proxyHeaderExclusiveList)
// Setup Proxy Headers and Proxy Headers Host
// Only send the Proxy White Listed Header names
self.proxyHeaders = constructProxyHeaderWhiteList(self.headers, proxyHeaderWhiteList)
self.proxyHeaders.host = constructProxyHost(self.uri)
proxyHeaderExclusiveList.forEach(self.removeHeader, self)
// Set Agent from Tunnel Data
var tunnelFn = getTunnelFn(self)
var tunnelOptions = constructTunnelOptions(self)
self.agent = tunnelFn(tunnelOptions)
return true
}
Request.prototype.init = function (options) {

@@ -462,5 +305,5 @@ // init() contains all the code to setup the request object.

self.tunnel = getTunnelOption(self, options)
self.tunnel = self._tunnel.isEnabled(options)
if (self.proxy) {
self.setupTunnel()
self._tunnel.setup(options)
}

@@ -763,3 +606,3 @@

if (self.proxy) {
if (self.setupTunnel()) {
if (self._tunnel.setup()) {
return

@@ -1559,6 +1402,6 @@ }

Request.defaultProxyHeaderWhiteList =
defaultProxyHeaderWhiteList.slice()
Tunnel.defaultProxyHeaderWhiteList.slice()
Request.defaultProxyHeaderExclusiveList =
defaultProxyHeaderExclusiveList.slice()
Tunnel.defaultProxyHeaderExclusiveList.slice()

@@ -1565,0 +1408,0 @@ // Exports

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc