11
22module . exports = exports = install
33
4+ module . exports . test = { download : download }
5+
46exports . usage = 'Install node development files for the specified node version.'
57
68/**
@@ -110,45 +112,6 @@ function install (gyp, argv, callback) {
110112 go ( )
111113 }
112114
113- function download ( url ) {
114- log . http ( 'GET' , url )
115-
116- var req = null
117- var requestOpts = {
118- uri : url
119- , headers : {
120- 'User-Agent' : 'node-gyp v' + gyp . version + ' (node ' + process . version + ')'
121- }
122- }
123-
124- // basic support for a proxy server
125- var proxyUrl = gyp . opts . proxy
126- || process . env . http_proxy
127- || process . env . HTTP_PROXY
128- || process . env . npm_config_proxy
129- if ( proxyUrl ) {
130- if ( / ^ h t t p s ? : \/ \/ / i. test ( proxyUrl ) ) {
131- log . verbose ( 'download' , 'using proxy url: "%s"' , proxyUrl )
132- requestOpts . proxy = proxyUrl
133- } else {
134- log . warn ( 'download' , 'ignoring invalid "proxy" config setting: "%s"' , proxyUrl )
135- }
136- }
137- try {
138- // The "request" constructor can throw sometimes apparently :(
139- // See: https://github.com/nodejs/node-gyp/issues/114
140- req = request ( requestOpts )
141- } catch ( e ) {
142- cb ( e )
143- }
144- if ( req ) {
145- req . on ( 'response' , function ( res ) {
146- log . http ( res . statusCode , url )
147- } )
148- }
149- return req
150- }
151-
152115 function getContentSha ( res , callback ) {
153116 var shasum = crypto . createHash ( 'sha256' )
154117 res . on ( 'data' , function ( chunk ) {
@@ -218,8 +181,11 @@ function install (gyp, argv, callback) {
218181 return
219182 }
220183
221- var req = download ( release . tarballUrl )
222- if ( ! req ) return
184+ try {
185+ var req = download ( gyp , process . env , release . tarballUrl )
186+ } catch ( e ) {
187+ return cb ( e )
188+ }
223189
224190 // something went wrong downloading the tarball?
225191 req . on ( 'error' , function ( err ) {
@@ -311,8 +277,12 @@ function install (gyp, argv, callback) {
311277 var shasumsPath = path . resolve ( devDir , 'SHASUMS256.txt' )
312278
313279 log . verbose ( 'checksum url' , release . shasumsUrl )
314- var req = download ( release . shasumsUrl )
315- if ( ! req ) return
280+ try {
281+ var req = download ( gyp , process . env , release . shasumsUrl )
282+ } catch ( e ) {
283+ return cb ( e )
284+ }
285+
316286 req . on ( 'error' , done )
317287 req . on ( 'response' , function ( res ) {
318288 if ( res . statusCode !== 200 ) {
@@ -358,8 +328,12 @@ function install (gyp, argv, callback) {
358328 if ( err ) return done ( err )
359329 log . verbose ( 'streaming 32-bit ' + release . name + '.lib to:' , libPath32 )
360330
361- var req = download ( release . libUrl32 )
362- if ( ! req ) return
331+ try {
332+ var req = download ( gyp , process . env , release . libUrl32 , cb )
333+ } catch ( e ) {
334+ return cb ( e )
335+ }
336+
363337 req . on ( 'error' , done )
364338 req . on ( 'response' , function ( res ) {
365339 if ( res . statusCode !== 200 ) {
@@ -384,8 +358,12 @@ function install (gyp, argv, callback) {
384358 if ( err ) return done ( err )
385359 log . verbose ( 'streaming 64-bit ' + release . name + '.lib to:' , libPath64 )
386360
387- var req = download ( release . libUrl64 )
388- if ( ! req ) return
361+ try {
362+ var req = download ( gyp , process . env , release . libUrl64 , cb )
363+ } catch ( e ) {
364+ return cb ( e )
365+ }
366+
389367 req . on ( 'error' , done )
390368 req . on ( 'response' , function ( res ) {
391369 if ( res . statusCode !== 200 ) {
@@ -444,3 +422,35 @@ function install (gyp, argv, callback) {
444422 }
445423
446424}
425+
426+ function download ( gyp , env , url ) {
427+ log . http ( 'GET' , url )
428+
429+ var requestOpts = {
430+ uri : url
431+ , headers : {
432+ 'User-Agent' : 'node-gyp v' + gyp . version + ' (node ' + process . version + ')'
433+ }
434+ }
435+
436+ // basic support for a proxy server
437+ var proxyUrl = gyp . opts . proxy
438+ || env . http_proxy
439+ || env . HTTP_PROXY
440+ || env . npm_config_proxy
441+ if ( proxyUrl ) {
442+ if ( / ^ h t t p s ? : \/ \/ / i. test ( proxyUrl ) ) {
443+ log . verbose ( 'download' , 'using proxy url: "%s"' , proxyUrl )
444+ requestOpts . proxy = proxyUrl
445+ } else {
446+ log . warn ( 'download' , 'ignoring invalid "proxy" config setting: "%s"' , proxyUrl )
447+ }
448+ }
449+
450+ var req = request ( requestOpts )
451+ req . on ( 'response' , function ( res ) {
452+ log . http ( res . statusCode , url )
453+ } )
454+
455+ return req
456+ }
0 commit comments