@@ -58,7 +58,8 @@ inherits(HttpsProxyAgent, Agent);
5858 * Default options for the "connect" opts object.
5959 */
6060
61- var defaults = { port : 443 } ;
61+ var defaults = { port : 80 } ;
62+ var secureDefaults = { port : 443 } ;
6263
6364/**
6465 * Called when the node-core HTTP client library is creating a new HTTP request.
@@ -68,14 +69,18 @@ var defaults = { port: 443 };
6869
6970function connect ( req , _opts , fn ) {
7071
72+ var proxy = this . proxy ;
73+ var secureProxy = this . secureProxy ;
74+ var secureEndpoint = this . secureEndpoint ;
75+
7176 // these `opts` are the connect options to connect to the destination endpoint
72- var opts = extend ( { } , this . proxy , defaults , _opts ) ;
77+ var opts = extend ( { } , proxy , secureEndpoint ? secureDefaults : defaults , _opts ) ;
7378
7479 var socket ;
75- if ( this . secureProxy ) {
76- socket = tls . connect ( this . proxy ) ;
80+ if ( secureProxy ) {
81+ socket = tls . connect ( proxy ) ;
7782 } else {
78- socket = net . connect ( this . proxy ) ;
83+ socket = net . connect ( proxy ) ;
7984 }
8085
8186 function read ( ) {
@@ -84,14 +89,13 @@ function connect (req, _opts, fn) {
8489 else socket . once ( 'readable' , read ) ;
8590 }
8691
87- var self = this ;
8892 function ondata ( b ) {
8993 //console.log(b.length, b, b.toString());
9094 // TODO: verify that the socket is properly connected, check response...
9195
9296 var sock = socket ;
9397
94- if ( self . secureEndpoint ) {
98+ if ( secureEndpoint ) {
9599 // since the proxy is connecting to an SSL server, we have
96100 // to upgrade this socket connection to an SSL connection
97101 opts . socket = socket ;
@@ -113,7 +117,7 @@ function connect (req, _opts, fn) {
113117
114118 var hostname = opts . host + ':' + opts . port ;
115119 var msg = 'CONNECT ' + hostname + ' HTTP/1.1\r\n' ;
116- var auth = this . proxy . auth ;
120+ var auth = proxy . auth ;
117121 if ( auth ) {
118122 msg += 'Proxy-Authorization: Basic ' + new Buffer ( auth ) . toString ( 'base64' ) + '\r\n' ;
119123 }
0 commit comments