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

no_proxy support #1176

Closed
wants to merge 3 commits into from
Closed

no_proxy support #1176

wants to merge 3 commits into from

Conversation

ballwood
Copy link

@ballwood ballwood commented Apr 14, 2017

Ported code across from the request library, which I know to work correctly - https://github.com/request/request.

Unsure of where to put the unit/integration tests, if someone could guide me I'll write them. There were 11 tests failing when running npm test when I forked and the same amount after I made the code change.

@bnoordhuis
Copy link
Member

Sorry for the delay. This needs some tests but I'm kind of surprised at how complex it still is. Is npm_config_no_proxy a thing?

@vbfox
Copy link

vbfox commented Jun 29, 2017

I'd really like to see that PR get merged.

For npm config exporting npm_config_no_proxy there is a PR open but I don't know if it'll ever get merged: npm/npm#14248 (Currently it can't be specified in npm config)

@ballwood
Copy link
Author

Hi, sorry I thought I replied to this last week, must have not pressed send. Yeah I noticed that PR was open and included it to future proof it but their work on it seems to have gone by the wayside.

I can have a look at the tests I'm just trying to understand them at the moment and work out something that works correctly.

@ballwood
Copy link
Author

ballwood commented Aug 6, 2017

@bnoordhuis wrote some small unit tests as I got some free time

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Left some comments. Thanks for following up.

@@ -423,6 +424,44 @@ function install (gyp, argv, callback) {

}

function formatHostname (hostname) {
// canonicalize the hostname, so that 'oogle.com' won't match 'google.com'
return hostname.replace(/^\.*/, '.').toLowerCase()
Copy link
Member

Choose a reason for hiding this comment

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

This transforms google.com into .google.com. I infer that is intentional but can you update the comment to make that more explicit? This behavior also seems only lightly tested.

Aside: can you capitalize and punctuate comments?

var zoneParts = zone.split(':', 2)
var zoneHost = formatHostname(zoneParts[0])
var zonePort = zoneParts[1]
var hasPort = zone.indexOf(':') > -1
Copy link
Member

Choose a reason for hiding this comment

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

Not wrong per se but can also be derived without re-scanning from zonePort !== undefined or zoneParts.length === 2.

var isMatchedAt = hostname.indexOf(noProxyZone.hostname)
var hostnameMatched = (
isMatchedAt > -1 &&
(isMatchedAt === hostname.length - noProxyZone.hostname.length)
Copy link
Member

Choose a reason for hiding this comment

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

Correct me if I'm wrong but isn't this just a circuitous way of saying hostname === noProxyZone.hostname?

Choose a reason for hiding this comment

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

IMO it's a suffix match

var noProxyUrl = gyp.opts.no_proxy
|| env.no_proxy
|| env.NO_PROXY
|| env.npm_config_no_proxy
Copy link
Member

Choose a reason for hiding this comment

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

This should probably go; the npm pull request wasn't merged.

|| env.npm_config_no_proxy
|| ''

if (noProxyUrl === '*' || (noProxyUrl !== '' && uriInNoProxy(url, noProxyUrl))) {
Copy link
Member

Choose a reason for hiding this comment

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

Long line; can you keep it under 80 columns? The parens around the && aren't necessary.

log.verbose('download', 'using proxy url: "%s"', proxyUrl)
requestOpts.proxy = proxyUrl
} else {
log.warn('download', 'ignoring invalid "proxy" config setting: "%s"', proxyUrl)
Copy link
Member

Choose a reason for hiding this comment

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

Ditto, long line.

@@ -0,0 +1,63 @@
var test = require('tape')
Copy link
Member

Choose a reason for hiding this comment

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

Can you add 'use strict';?


t.equal(req.opts.proxy, gyp.opts.proxy)
t.equal(req.opts.uri, url)

Copy link
Member

Choose a reason for hiding this comment

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

Can you drop the blank line here and below?

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Wups sorry, meant to request changes. Only had one cup of coffee so far.

@maclover7
Copy link
Contributor

ping @ballwood

@dlangerenken
Copy link

@bnoordhuis is someone taking care of this PR? Seems like @ballwood is no longer working on it. It would be really nice to have in master.

@rvagg
Copy link
Member

rvagg commented Jun 21, 2019

This looks pretty good and we have HTTPS_PROXY support about to land too but it's going to need a new champion. If someone wants this in, please take this code, clean it up as per the suggestions in here and make it work against master. Tests would be good too if you can come up with some that are meaningful.

@rvagg rvagg closed this Jun 21, 2019
@imatlopez
Copy link
Contributor

imatlopez commented Nov 27, 2019

@rvagg I was looking at doing just this given this is quite a pain point inside our corporate network, however is of this approach to make it independent of requests? Would it be simpler to set the environment variables from the cli flags as needed and let requests do its job?

@rvagg
Copy link
Member

rvagg commented Nov 28, 2019

@imatlopez you mean request not requests right? Apparently obeys no_proxy these days but I don't know what we would need to do here, if anything, for that support to flow through. If it's obeying environment variables then I'd assume we don't have to do anything on our end, just set the env var before calling. If you need gyp.opts to be able to carry it then I guess some additional work could go in here and hopefully that'd be simple. You're welcome to open a PR if you'd like it added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants