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

Fix tunneling after redirection from https #1881

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions README.md
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
4 changes: 3 additions & 1 deletion lib/redirect.js
Expand Up @@ -135,6 +135,8 @@ Redirect.prototype.onResponse = function (response) {
// changing ports or protocols). This matches the behavior of curl:
// https://github.com/bagder/curl/blob/6beb0eee/lib/http.c#L710
request.removeHeader('authorization')
delete request.options.auth
delete request.options.oauth
Copy link
Member

Choose a reason for hiding this comment

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

This does not appear related to the tunneling changes, can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right.. This is related to init changes in redirect.js, not tunneling.

}
}
}
Expand All @@ -145,7 +147,7 @@ Redirect.prototype.onResponse = function (response) {

request.emit('redirect')

request.init()
request.init(request.options)
Copy link
Member

Choose a reason for hiding this comment

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

This makes me nervous.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that re-calling init with original options is better. Well, is this bad idea?

Copy link
Member

Choose a reason for hiding this comment

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

@falms it might be better, but given the existing code base it's better to keep things consistent instead of adding even more noise.


return true
}
Expand Down
15 changes: 3 additions & 12 deletions lib/tunnel.js
Expand Up @@ -113,14 +113,7 @@ function Tunnel (request) {

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
}
// 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') {
Expand All @@ -132,10 +125,8 @@ Tunnel.prototype.isEnabled = function (options) {
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
1 change: 1 addition & 0 deletions request.js
Expand Up @@ -137,6 +137,7 @@ function Request (options) {
self._redirect = new Redirect(self)
self._tunnel = new Tunnel(self)
self.init(options)
self.options = options
Copy link
Member

Choose a reason for hiding this comment

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

This has a bit of a bad code smell because we already set lots of properties on self and want to be careful about adding more without good naming and clear reasons.

}

util.inherits(Request, stream.Stream)
Expand Down
2 changes: 1 addition & 1 deletion tests/test-tunnel.js
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