@@ -1076,14 +1076,16 @@ exports.globalAgent = globalAgent;
10761076function ClientRequest ( options , cb ) {
10771077 var self = this ;
10781078 OutgoingMessage . call ( self ) ;
1079- self . agent = options . agent ;
1080- options . defaultPort = options . defaultPort || 80 ;
10811079
1082- options . port = options . port || options . defaultPort ;
1083- options . host = options . hostname || options . host || 'localhost' ;
1080+ self . agent = options . agent === undefined ? globalAgent : options . agent ;
1081+
1082+ var defaultPort = options . defaultPort || 80 ;
1083+
1084+ var port = options . port || defaultPort ;
1085+ var host = options . hostname || options . host || 'localhost' ;
10841086
10851087 if ( options . setHost === undefined ) {
1086- options . setHost = true ;
1088+ var setHost = true ;
10871089 }
10881090
10891091 self . socketPath = options . socketPath ;
@@ -1102,10 +1104,10 @@ function ClientRequest(options, cb) {
11021104 self . setHeader ( key , options . headers [ key ] ) ;
11031105 }
11041106 }
1105- if ( options . host && ! this . getHeader ( 'host' ) && options . setHost ) {
1106- var hostHeader = options . host ;
1107- if ( options . port && + options . port !== options . defaultPort ) {
1108- hostHeader += ':' + options . port ;
1107+ if ( host && ! this . getHeader ( 'host' ) && setHost ) {
1108+ var hostHeader = host ;
1109+ if ( port && + port !== defaultPort ) {
1110+ hostHeader += ':' + port ;
11091111 }
11101112 this . setHeader ( 'Host' , hostHeader ) ;
11111113 }
@@ -1142,15 +1144,15 @@ function ClientRequest(options, cb) {
11421144 // If there is an agent we should default to Connection:keep-alive.
11431145 self . _last = false ;
11441146 self . shouldKeepAlive = true ;
1145- self . agent . addRequest ( self , options . host , options . port ) ;
1147+ self . agent . addRequest ( self , host , port ) ;
11461148 } else {
11471149 // No agent, default to Connection:close.
11481150 self . _last = true ;
11491151 self . shouldKeepAlive = false ;
11501152 if ( options . createConnection ) {
1151- var conn = options . createConnection ( options . port , options . host , options ) ;
1153+ var conn = options . createConnection ( port , host , options ) ;
11521154 } else {
1153- var conn = net . createConnection ( options . port , options . host ) ;
1155+ var conn = net . createConnection ( port , host ) ;
11541156 }
11551157 self . onSocket ( conn ) ;
11561158 }
@@ -1426,15 +1428,10 @@ exports.request = function(options, cb) {
14261428 throw new Error ( 'Protocol:' + options . protocol + ' not supported.' ) ;
14271429 }
14281430
1429- if ( options . agent === undefined ) {
1430- options . agent = globalAgent ;
1431- }
1432-
14331431 return new ClientRequest ( options , cb ) ;
14341432} ;
14351433
14361434exports . get = function ( options , cb ) {
1437- options . method = 'GET' ;
14381435 var req = exports . request ( options , cb ) ;
14391436 req . end ( ) ;
14401437 return req ;
0 commit comments