Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2012-07-11 23:53:27 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2012-07-20 01:49:30 +0400
commit53716eb0b5338999761d115fad9d392077836e63 (patch)
treee726a89f587c7ce676d4b9d81282e35d73540cf7 /lib/http.js
parent1fa0bca2ad58ad1d91557f8ae7f467370c0290d6 (diff)
http/https: pass request to .createConnection()
It's useful for passing some additional options of request object to the underlying API
Diffstat (limited to 'lib/http.js')
-rw-r--r--lib/http.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/http.js b/lib/http.js
index 01aa4ebde80..eccea994483 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -1067,7 +1067,7 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) {
}
if (this.sockets[name].length < this.maxSockets) {
// If we are under maxSockets create a new one.
- req.onSocket(this.createSocket(name, host, port, localAddress));
+ req.onSocket(this.createSocket(name, host, port, localAddress, req));
} else {
// We are over limit so we'll add it to the queue.
if (!this.requests[name]) {
@@ -1076,13 +1076,13 @@ Agent.prototype.addRequest = function(req, host, port, localAddress) {
this.requests[name].push(req);
}
};
-Agent.prototype.createSocket = function(name, host, port, localAddress) {
+Agent.prototype.createSocket = function(name, host, port, localAddress, req) {
var self = this;
var options = util._extend({}, self.options);
options.port = port;
options.host = host;
options.localAddress = localAddress;
- var s = self.createConnection(options);
+ var s = self.createConnection.call(req, options);
if (!self.sockets[name]) {
self.sockets[name] = [];
}
@@ -1123,7 +1123,13 @@ Agent.prototype.removeSocket = function(s, name, host, port, localAddress) {
}
if (this.requests[name] && this.requests[name].length) {
// If we have pending requests and a socket gets closed a new one
- this.createSocket(name, host, port, localAddress).emit('free');
+ this.createSocket(
+ name,
+ host,
+ port,
+ localAddress,
+ this.requests[name][0]
+ ).emit('free');
}
};
@@ -1135,6 +1141,7 @@ function ClientRequest(options, cb) {
var self = this;
OutgoingMessage.call(self);
+ this.options = options;
self.agent = options.agent === undefined ? globalAgent : options.agent;
var defaultPort = options.defaultPort || 80;
@@ -1194,7 +1201,7 @@ function ClientRequest(options, cb) {
self._last = true;
self.shouldKeepAlive = false;
if (options.createConnection) {
- self.onSocket(options.createConnection(self.socketPath));
+ self.onSocket(options.createConnection.call(self, self.socketPath));
} else {
self.onSocket(net.createConnection(self.socketPath));
}
@@ -1210,7 +1217,7 @@ function ClientRequest(options, cb) {
if (options.createConnection) {
options.port = port;
options.host = host;
- var conn = options.createConnection(options);
+ var conn = options.createConnection.call(self, options);
} else {
var conn = net.createConnection({
port: port,