From c226f8176827067a0c1404655da1295f62cf0083 Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 4 Jun 2009 15:41:40 +0200 Subject: [PATCH] Fix HTTP client output bug. --- src/http.js | 19 ++++++++++++++----- src/net.cc | 3 +-- test_client.js | 4 ++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/http.js b/src/http.js index 64d029f0c8..6f878c0607 100644 --- a/src/http.js +++ b/src/http.js @@ -324,6 +324,7 @@ node.http.Client = function (port, host) { var self = this; function ClientRequest (method, uri, header_lines) { + this.uri = uri; var chunked_encoding = false; this.closeOnFinish = false; @@ -364,7 +365,8 @@ node.http.Client = function (port, host) { } header += CRLF; - var output = [header]; + var output = []; + send(output, header); this.sendBody = function (chunk, encoding) { if (chunked_encoding) { @@ -380,12 +382,13 @@ node.http.Client = function (port, host) { }; this.flush = function ( ) { - if (connection.readyState !== "open") { + if (connection.readyState == "closed") { connection.connect(port, host); return; } while (this === requests[0] && output.length > 0) { - connection.send(output.shift()); + var out = output.shift(); + connection.send(out[0], out[1]); } }; @@ -400,17 +403,23 @@ node.http.Client = function (port, host) { } connection.onConnect = function () { - //node.debug("HTTP CLIENT: connected"); + //node.debug("HTTP CLIENT onConnect. readyState = " + connection.readyState); + //node.debug("requests[0].uri = " + requests[0].uri); requests[0].flush(); }; + connection.onEOF = function () { + //node.debug("onEOF. readyState = " + connection.readyState); + connection.close(); + }; + connection.onDisconnect = function (had_error) { if (had_error) { if (self.onError) self.onError(); return; } - //node.debug("HTTP CLIENT: disconnect"); + //node.debug("HTTP CLIENT onDisconnect. readyState = " + connection.readyState); // If there are more requests to handle, reconnect. if (requests.length > 0) { //node.debug("HTTP CLIENT: reconnecting"); diff --git a/src/net.cc b/src/net.cc index aea6b956ee..0fda98e065 100644 --- a/src/net.cc +++ b/src/net.cc @@ -185,13 +185,12 @@ Connection::Connect (const Arguments& args) * http://lists.schmorp.de/pipermail/libev/2009q1/000632.html */ eio_warmup(); + connection->Attach(); eio_custom( Connection::Resolve , EIO_PRI_DEFAULT , Connection::AfterResolve , connection ); - - connection->Attach(); return Undefined(); } diff --git a/test_client.js b/test_client.js index 56e0137805..02ba11956c 100644 --- a/test_client.js +++ b/test_client.js @@ -21,8 +21,8 @@ req.finish(function (res) { }); setTimeout(function () { - var req2 = c.get("/something/else", []); - puts("start req2"); + var req2 = c.get("/something/else"); + //node.debug("start req2"); req2.finish(function (res) { puts("response 2: " + res.statusCode.toString());