Browse Source

Factor out a http.Client._reconnect() function

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
9d4d232eaa
  1. 55
      lib/http.js

55
lib/http.js

@ -457,18 +457,35 @@ exports.createClient = function (port, host) {
var requests = []; var requests = [];
var currentRequest; var currentRequest;
client.tcpSetSecure = client.setSecure;
client.setSecure = function(format_type, ca_certs, crl_list, private_key, certificate) {
secure_credentials.secure = true;
secure_credentials.format_type = format_type;
secure_credentials.ca_certs = ca_certs;
secure_credentials.crl_list = crl_list;
secure_credentials.private_key = private_key;
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) { client._pushRequest = function (req) {
req.addListener("flush", function () { req.addListener("flush", function () {
if (client.readyState == "closed") { if (client.readyState == "closed") {
//sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState); //sys.debug("HTTP CLIENT request flush. reconnect. readyState = " + client.readyState);
client.connect(port, host); // reconnect client._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; return;
} }
//sys.debug("client flush readyState = " + client.readyState); //sys.debug("client flush readyState = " + client.readyState);
@ -477,16 +494,6 @@ exports.createClient = function (port, host) {
requests.push(req); requests.push(req);
}; };
client.tcpSetSecure = client.setSecure;
client.setSecure = function(format_type, ca_certs, crl_list, private_key, certificate) {
secure_credentials.secure = true;
secure_credentials.format_type = format_type;
secure_credentials.ca_certs = ca_certs;
secure_credentials.crl_list = crl_list;
secure_credentials.private_key = private_key;
secure_credentials.certificate = certificate;
}
client.addListener("connect", function () { client.addListener("connect", function () {
client.resetParser(); client.resetParser();
currentRequest = requests.shift(); currentRequest = requests.shift();
@ -507,16 +514,8 @@ exports.createClient = function (port, host) {
//sys.debug("HTTP CLIENT onClose. readyState = " + client.readyState); //sys.debug("HTTP CLIENT onClose. readyState = " + client.readyState);
// If there are more requests to handle, reconnect. // If there are more requests to handle, reconnect.
if (requests.length > 0 && client.readyState != "opening") { if (requests.length > 0) {
//sys.debug("HTTP CLIENT: reconnecting readyState = " + client.readyState); client._reconnect();
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);
}
} }
}); });

Loading…
Cancel
Save