23
23
'use strict' ;
24
24
25
25
const http = require ( 'http' ) ;
26
+ const https = require ( 'https' ) ;
26
27
const url = require ( 'url' ) ;
27
28
28
29
const cmd = require ( '../lib/command' ) ;
@@ -233,13 +234,15 @@ class HttpClient {
233
234
* @private {{auth: (?string|undefined),
234
235
* host: string,
235
236
* path: (?string|undefined),
236
- * port: (?string|undefined)}}
237
+ * port: (?string|undefined),
238
+ * protocol: (?string|undefined)}}
237
239
*/
238
240
this . options_ = {
239
241
auth : parsedUrl . auth ,
240
242
host : parsedUrl . hostname ,
241
243
path : parsedUrl . pathname ,
242
- port : parsedUrl . port
244
+ port : parsedUrl . port ,
245
+ protocol : parsedUrl . protocol
243
246
} ;
244
247
}
245
248
@@ -279,6 +282,7 @@ class HttpClient {
279
282
auth : this . options_ . auth ,
280
283
host : this . options_ . host ,
281
284
port : this . options_ . port ,
285
+ protocol : this . options_ . protocol ,
282
286
path : path ,
283
287
headers : headers
284
288
} ;
@@ -321,7 +325,8 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
321
325
}
322
326
}
323
327
324
- var request = http . request ( options , function ( response ) {
328
+ let requestFn = options . protocol === 'https:' ? https . request : http . request ;
329
+ var request = requestFn ( options , function onResponse ( response ) {
325
330
if ( response . statusCode == 302 || response . statusCode == 303 ) {
326
331
try {
327
332
var location = url . parse ( response . headers [ 'location' ] ) ;
@@ -344,6 +349,7 @@ function sendRequest(options, onOk, onError, opt_data, opt_proxy) {
344
349
host : location . hostname ,
345
350
path : location . pathname + ( location . search || '' ) ,
346
351
port : location . port ,
352
+ protocol : location . protocol ,
347
353
headers : {
348
354
'Accept' : 'application/json; charset=utf-8'
349
355
}
0 commit comments