mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Factor out a http.Client._reconnect() function
This commit is contained in:
59
lib/http.js
59
lib/http.js
@@ -457,26 +457,6 @@ exports.createClient = function (port, host) {
|
||||
var requests = [];
|
||||
var currentRequest;
|
||||
|
||||
client._pushRequest = function (req) {
|
||||
req.addListener("flush", function () {
|
||||
if (client.readyState == "closed") {
|
||||
//sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
|
||||
client.connect(port, host); // reconnect
|
||||
if (secure_credentials.secure) {
|
||||
client.tcpSetSecure(secure_credentials.format_type,
|
||||
secure_credentials.ca_certs,
|
||||
secure_credentials.crl_list,
|
||||
secure_credentials.private_key,
|
||||
secure_credentials.certificate);
|
||||
}
|
||||
return;
|
||||
}
|
||||
//sys.debug("client flush readyState = " + client.readyState);
|
||||
if (req == currentRequest) flushMessageQueue(client, [req]);
|
||||
});
|
||||
requests.push(req);
|
||||
};
|
||||
|
||||
client.tcpSetSecure = client.setSecure;
|
||||
client.setSecure = function(format_type, ca_certs, crl_list, private_key, certificate) {
|
||||
secure_credentials.secure = true;
|
||||
@@ -487,6 +467,33 @@ exports.createClient = function (port, host) {
|
||||
secure_credentials.certificate = certificate;
|
||||
}
|
||||
|
||||
client._reconnect = function () {
|
||||
if (client.readyState != "opening") {
|
||||
//sys.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
|
||||
client.connect(port, host);
|
||||
if (secure_credentials.secure) {
|
||||
client.tcpSetSecure(secure_credentials.format_type,
|
||||
secure_credentials.ca_certs,
|
||||
secure_credentials.crl_list,
|
||||
secure_credentials.private_key,
|
||||
secure_credentials.certificate);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
client._pushRequest = function (req) {
|
||||
req.addListener("flush", function () {
|
||||
if (client.readyState == "closed") {
|
||||
//sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
|
||||
client._reconnect();
|
||||
return;
|
||||
}
|
||||
//sys.debug("client flush readyState = " + client.readyState);
|
||||
if (req == currentRequest) flushMessageQueue(client, [req]);
|
||||
});
|
||||
requests.push(req);
|
||||
};
|
||||
|
||||
client.addListener("connect", function () {
|
||||
client.resetParser();
|
||||
currentRequest = requests.shift();
|
||||
@@ -507,16 +514,8 @@ exports.createClient = function (port, host) {
|
||||
//sys.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
|
||||
|
||||
// If there are more requests to handle, reconnect.
|
||||
if (requests.length > 0 && client.readyState != "opening") {
|
||||
//sys.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState);
|
||||
client.connect(port, host); // reconnect
|
||||
if (secure_credentials.secure) {
|
||||
client.tcpSetSecure(secure_credentials.format_type,
|
||||
secure_credentials.ca_certs,
|
||||
secure_credentials.crl_list,
|
||||
secure_credentials.private_key,
|
||||
secure_credentials.certificate);
|
||||
}
|
||||
if (requests.length > 0) {
|
||||
client._reconnect();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user