Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise Setup Tunnel Function #1389

Merged
merged 2 commits into from Jan 31, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why split this into 2 lines?

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