Skip to content

Commit

Permalink
Merge pull request #1389 from request/support/setup-tunnel-refactor
Browse files Browse the repository at this point in the history
Revise Setup Tunnel Function
  • Loading branch information
nylen committed Jan 31, 2015
2 parents 2c87bbf + ce0cc4a commit 001c13f
Showing 1 changed file with 11 additions and 28 deletions.
39 changes: 11 additions & 28 deletions request.js
Expand Up @@ -270,50 +270,33 @@ function debug() {
}

Request.prototype.setupTunnel = function () {
// Set up the tunneling agent if necessary
// Only send the proxy whitelisted header names.
// Turn on tunneling for the rest of request.

var self = this

if (typeof self.proxy === 'string') {
self.proxy = url.parse(self.proxy)
}

if (!self.proxy) {
return false
}

if (!self.tunnel) {

if (!self.proxy || !self.tunnel) {
return false
}

// Always include `defaultProxyHeaderExclusiveList`

if (!self.proxyHeaderExclusiveList) {
self.proxyHeaderExclusiveList = []
}

// Setup Proxy Header Exclusive List and White List
self.proxyHeaderExclusiveList = self.proxyHeaderExclusiveList || []
self.proxyHeaderWhiteList = self.proxyHeaderWhiteList || defaultProxyHeaderWhiteList
var proxyHeaderExclusiveList = self.proxyHeaderExclusiveList.concat(defaultProxyHeaderExclusiveList)

// Treat `proxyHeaderExclusiveList` as part of `proxyHeaderWhiteList`

if (!self.proxyHeaderWhiteList) {
self.proxyHeaderWhiteList = defaultProxyHeaderWhiteList
}

var proxyHeaderWhiteList = self.proxyHeaderWhiteList.concat(proxyHeaderExclusiveList)

var proxyHost = constructProxyHost(self.uri)
// Setup Proxy Headers and Proxy Headers Host
// Only send the Proxy White Listed Header names
self.proxyHeaders = constructProxyHeaderWhiteList(self.headers, proxyHeaderWhiteList)
self.proxyHeaders.host = proxyHost

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
}

Expand Down

0 comments on commit 001c13f

Please sign in to comment.