Skip to content

Commit

Permalink
Refactor setup tunnel a little
Browse files Browse the repository at this point in the history
  • Loading branch information
seanstrom committed Jan 30, 2015
1 parent 2c87bbf commit 0c59203
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions request.js
Expand Up @@ -270,50 +270,35 @@ 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)

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

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 0c59203

Please sign in to comment.