@@ -1067,7 +1067,7 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) {
1067
1067
}
1068
1068
if ( this . sockets [ name ] . length < this . maxSockets ) {
1069
1069
// If we are under maxSockets create a new one.
1070
- req . onSocket ( this . createSocket ( name , host , port , localAddress ) ) ;
1070
+ req . onSocket ( this . createSocket ( name , host , port , localAddress , req ) ) ;
1071
1071
} else {
1072
1072
// We are over limit so we'll add it to the queue.
1073
1073
if ( ! this . requests [ name ] ) {
@@ -1076,13 +1076,13 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) {
1076
1076
this . requests [ name ] . push ( req ) ;
1077
1077
}
1078
1078
} ;
1079
- Agent . prototype . createSocket = function ( name , host , port , localAddress ) {
1079
+ Agent . prototype . createSocket = function ( name , host , port , localAddress , req ) {
1080
1080
var self = this ;
1081
1081
var options = util . _extend ( { } , self . options ) ;
1082
1082
options . port = port ;
1083
1083
options . host = host ;
1084
1084
options . localAddress = localAddress ;
1085
- var s = self . createConnection ( options ) ;
1085
+ var s = self . createConnection . call ( req , options ) ;
1086
1086
if ( ! self . sockets [ name ] ) {
1087
1087
self . sockets [ name ] = [ ] ;
1088
1088
}
@@ -1123,7 +1123,13 @@ Agent.prototype.removeSocket = function(s, name, host, port, localAddress) {
1123
1123
}
1124
1124
if ( this . requests [ name ] && this . requests [ name ] . length ) {
1125
1125
// If we have pending requests and a socket gets closed a new one
1126
- this . createSocket ( name , host , port , localAddress ) . emit ( 'free' ) ;
1126
+ this . createSocket (
1127
+ name ,
1128
+ host ,
1129
+ port ,
1130
+ localAddress ,
1131
+ this . requests [ name ] [ 0 ]
1132
+ ) . emit ( 'free' ) ;
1127
1133
}
1128
1134
} ;
1129
1135
@@ -1135,6 +1141,7 @@ function ClientRequest(options, cb) {
1135
1141
var self = this ;
1136
1142
OutgoingMessage . call ( self ) ;
1137
1143
1144
+ this . options = options ;
1138
1145
self . agent = options . agent === undefined ? globalAgent : options . agent ;
1139
1146
1140
1147
var defaultPort = options . defaultPort || 80 ;
@@ -1194,7 +1201,7 @@ function ClientRequest(options, cb) {
1194
1201
self . _last = true ;
1195
1202
self . shouldKeepAlive = false ;
1196
1203
if ( options . createConnection ) {
1197
- self . onSocket ( options . createConnection ( self . socketPath ) ) ;
1204
+ self . onSocket ( options . createConnection . call ( self , self . socketPath ) ) ;
1198
1205
} else {
1199
1206
self . onSocket ( net . createConnection ( self . socketPath ) ) ;
1200
1207
}
@@ -1210,7 +1217,7 @@ function ClientRequest(options, cb) {
1210
1217
if ( options . createConnection ) {
1211
1218
options . port = port ;
1212
1219
options . host = host ;
1213
- var conn = options . createConnection ( options ) ;
1220
+ var conn = options . createConnection . call ( self , options ) ;
1214
1221
} else {
1215
1222
var conn = net . createConnection ( {
1216
1223
port : port ,
0 commit comments