@@ -14,6 +14,7 @@ const makeDir = require('make-dir');
14
14
// for fetching binaries
15
15
const fetch = require ( 'node-fetch' ) ;
16
16
const tar = require ( 'tar' ) ;
17
+ const url = require ( 'url' ) ;
17
18
18
19
let npgVersion = 'unknown' ;
19
20
try {
24
25
// do nothing
25
26
}
26
27
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
+
27
56
function place_binary ( uri , targetDir , opts , callback ) {
28
57
log . http ( 'GET' , uri ) ;
29
58
@@ -54,8 +83,18 @@ function place_binary(uri, targetDir, opts, callback) {
54
83
process . env . http_proxy ||
55
84
process . env . HTTP_PROXY ||
56
85
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
+
57
96
let agent ;
58
- if ( proxyUrl ) {
97
+ if ( proxyUrl && should_proxy ( sanitized , noProxyList ) ) {
59
98
const ProxyAgent = require ( 'https-proxy-agent' ) ;
60
99
agent = new ProxyAgent ( proxyUrl ) ;
61
100
log . http ( 'download' , 'proxy agent configured using: "%s"' , proxyUrl ) ;
0 commit comments