@@ -14,6 +14,7 @@ const makeDir = require('make-dir');
1414// for fetching binaries
1515const fetch = require ( 'node-fetch' ) ;
1616const tar = require ( 'tar' ) ;
17+ const url = require ( 'url' ) ;
1718
1819let npgVersion = 'unknown' ;
1920try {
2425 // do nothing
2526}
2627
28+ function should_proxy ( uri , noProxyList ) {
29+ const { hostname, port } = url . parse ( uri ) ;
30+
31+ /* TODO: Default ports as defined by the protocol should still
32+ match, they currently will not if the noProxyList entry
33+ explicitly specifies the default port. */
34+
35+ // eslint-disable-next-line eqeqeq
36+ const portMatch = ( entry ) => entry . port === undefined || entry . port == port ;
37+
38+ for ( let i = 0 ; i < noProxyList && noProxyList . length ; i ++ ) {
39+ const entry = noProxyList [ i ] ;
40+ if ( ! portMatch ( entry ) ) {
41+ continue ;
42+ }
43+ // TODO: Deal with 'partial wildcards': *.foo.com
44+ if ( entry . hostSuffix === '*' ) {
45+ return false ;
46+ }
47+ const rightSideMatch = hostname . indexOf ( entry . hostSuffix , hostname . length , entry . hostSuffix . length ) ;
48+ if ( rightSideMatch > - 1 ) {
49+ return false ;
50+ }
51+ }
52+
53+ return true ;
54+ }
55+
2756function place_binary ( uri , targetDir , opts , callback ) {
2857 log . http ( 'GET' , uri ) ;
2958
@@ -54,8 +83,18 @@ function place_binary(uri, targetDir, opts, callback) {
5483 process . env . http_proxy ||
5584 process . env . HTTP_PROXY ||
5685 process . env . npm_config_proxy ;
86+ const noProxy = opts . noproxy ||
87+ process . env . no_proxy ||
88+ process . env . NO_PROXY ||
89+ process . env . npm_config_noproxy ;
90+ // TODO: IPv6 address + port support.
91+ const noProxyList = noProxy && noProxy . split ( ',' ) . map ( ( e ) => {
92+ const [ hostSuffix , port ] = e . split ( ':' ) ;
93+ return { hostSuffix, port } ;
94+ } ) ;
95+
5796 let agent ;
58- if ( proxyUrl ) {
97+ if ( proxyUrl && should_proxy ( sanitized , noProxyList ) ) {
5998 const ProxyAgent = require ( 'https-proxy-agent' ) ;
6099 agent = new ProxyAgent ( proxyUrl ) ;
61100 log . http ( 'download' , 'proxy agent configured using: "%s"' , proxyUrl ) ;
0 commit comments