Skip to content

Commit

Permalink
Merge pull request #1894 from falms/fix-tunneling-after-redirection-s…
Browse files Browse the repository at this point in the history
…imple

Fix tunneling after redirection from https (Original: #1881)
  • Loading branch information
simov committed Nov 9, 2015
2 parents 8b2a20c + 7943dce commit 973f0ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,7 @@ default in Linux can be anywhere from 20-120 seconds][linux-timeout]).
- `tunnel` - controls the behavior of
[HTTP `CONNECT` tunneling](https://en.wikipedia.org/wiki/HTTP_tunnel#HTTP_CONNECT_tunneling)
as follows:
- `undefined` (default) - `true` if the destination is `https` or a previous
request in the redirect chain used a tunneling proxy, `false` otherwise
- `undefined` (default) - `true` if the destination is `https`, `false` otherwise
- `true` - always tunnel to the destination by making a `CONNECT` request to
the proxy
- `false` - request the destination as a `GET` request.
Expand Down
29 changes: 12 additions & 17 deletions lib/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,28 @@ function Tunnel (request) {
this.request = request
this.proxyHeaderWhiteList = defaultProxyHeaderWhiteList
this.proxyHeaderExclusiveList = []
}

Tunnel.prototype.isEnabled = function (options) {
var request = this.request
// 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 request.tunnel !== 'undefined') {
return request.tunnel
this.tunnelOverride = request.tunnel
}
}

Tunnel.prototype.isEnabled = function () {
var self = this
, request = self.request
// Tunnel HTTPS by default. Allow the user to override this setting.

// If options.tunnel is set (the user specified a value), use it.
if (typeof options.tunnel !== 'undefined') {
return options.tunnel
// If self.tunnelOverride is set (the user specified a value), use it.
if (typeof self.tunnelOverride !== 'undefined') {
return self.tunnelOverride
}

// If the destination is HTTPS, tunnel.
if (request.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
// Otherwise, do not use tunnel.
return false
}

Tunnel.prototype.setup = function (options) {
Expand Down
2 changes: 1 addition & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ Request.prototype.init = function (options) {
self.proxy = getProxyFromURI(self.uri)
}

self.tunnel = self._tunnel.isEnabled(options)
self.tunnel = self._tunnel.isEnabled()
if (self.proxy) {
self._tunnel.setup(options)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test-tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ runTest('https->http over http, tunnel=default', {
}, [
'http connect to localhost:' + ss.port,
'https redirect to http',
'http connect to localhost:' + s.port,
'http proxy to http',
'http response',
'200 http ok'
])
Expand Down

0 comments on commit 973f0ee

Please sign in to comment.