From c457b829e29574e9aeb7a71a6197b08deb06d485 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 4 Jun 2009 12:36:08 +0200 Subject: [PATCH] If http.Client has an error, do not continue to reconnect. --- src/http.js | 8 +++++++- test_client.js | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/http.js b/src/http.js index ae6fb6979a..64d029f0c8 100644 --- a/src/http.js +++ b/src/http.js @@ -321,6 +321,7 @@ node.http.Server = function (RequestHandler, options) { node.http.Client = function (port, host) { var connection = new node.http.LowLevelClient(); var requests = []; + var self = this; function ClientRequest (method, uri, header_lines) { @@ -403,7 +404,12 @@ node.http.Client = function (port, host) { requests[0].flush(); }; - connection.onDisconnect = function () { + connection.onDisconnect = function (had_error) { + if (had_error) { + if (self.onError) self.onError(); + return; + } + //node.debug("HTTP CLIENT: disconnect"); // If there are more requests to handle, reconnect. if (requests.length > 0) { diff --git a/test_client.js b/test_client.js index eec918da1c..56e0137805 100644 --- a/test_client.js +++ b/test_client.js @@ -1,5 +1,9 @@ var c = new node.http.Client(8000, "127.0.0.1"); +c.onError = function () { + puts("http client connection error."); +}; + var req = c.get("/bytes/123", [["Accept", "*/*"]]); req.finish(function (res) { puts("response 1: " + res.statusCode.toString());