@@ -107,6 +107,11 @@ describe('HttpsProxyAgent', function () {
107
107
assert . equal ( '127.0.0.1' , agent . proxy . host ) ;
108
108
assert . equal ( proxyPort , agent . proxy . port ) ;
109
109
} ) ;
110
+ it ( 'should set a `defaultPort` property' , function ( ) {
111
+ var opts = url . parse ( "http://127.0.0.1:" + proxyPort ) ;
112
+ var agent = new HttpsProxyAgent ( opts ) ;
113
+ assert . equal ( 443 , agent . defaultPort ) ;
114
+ } ) ;
110
115
describe ( 'secureProxy' , function ( ) {
111
116
it ( 'should default to `false`' , function ( ) {
112
117
var agent = new HttpsProxyAgent ( { port : proxyPort } ) ;
@@ -303,6 +308,35 @@ describe('HttpsProxyAgent', function () {
303
308
} ) ;
304
309
} ) ;
305
310
311
+ it ( 'should not send a port number for the default port' , function ( done ) {
312
+ sslServer . once ( 'request' , function ( req , res ) {
313
+ res . end ( JSON . stringify ( req . headers ) ) ;
314
+ } ) ;
315
+
316
+ var proxy = process . env . HTTPS_PROXY || process . env . https_proxy || "https://127.0.0.1:" + sslProxyPort ;
317
+ proxy = url . parse ( proxy ) ;
318
+ proxy . rejectUnauthorized = false ;
319
+ var agent = new HttpsProxyAgent ( proxy ) ;
320
+ agent . defaultPort = sslServerPort ;
321
+
322
+ var opts = url . parse ( "https://127.0.0.1:" + sslServerPort ) ;
323
+ opts . agent = agent ;
324
+ opts . rejectUnauthorized = false ;
325
+
326
+ https . get ( opts , function ( res ) {
327
+ var data = "" ;
328
+ res . setEncoding ( "utf8" ) ;
329
+ res . on ( "data" , function ( b ) {
330
+ data += b ;
331
+ } ) ;
332
+ res . on ( "end" , function ( ) {
333
+ data = JSON . parse ( data ) ;
334
+ assert . equal ( "127.0.0.1" , data . host ) ;
335
+ done ( ) ;
336
+ } ) ;
337
+ } ) ;
338
+ } ) ;
339
+
306
340
} ) ;
307
341
308
342
} ) ;
0 commit comments