Browse Source

Fix HTTP client output bug.

v0.7.4-release
Ryan 16 years ago
parent
commit
c226f81768
  1. 19
      src/http.js
  2. 3
      src/net.cc
  3. 4
      test_client.js

19
src/http.js

@ -324,6 +324,7 @@ node.http.Client = function (port, host) {
var self = this; var self = this;
function ClientRequest (method, uri, header_lines) { function ClientRequest (method, uri, header_lines) {
this.uri = uri;
var chunked_encoding = false; var chunked_encoding = false;
this.closeOnFinish = false; this.closeOnFinish = false;
@ -364,7 +365,8 @@ node.http.Client = function (port, host) {
} }
header += CRLF; header += CRLF;
var output = [header]; var output = [];
send(output, header);
this.sendBody = function (chunk, encoding) { this.sendBody = function (chunk, encoding) {
if (chunked_encoding) { if (chunked_encoding) {
@ -380,12 +382,13 @@ node.http.Client = function (port, host) {
}; };
this.flush = function ( ) { this.flush = function ( ) {
if (connection.readyState !== "open") { if (connection.readyState == "closed") {
connection.connect(port, host); connection.connect(port, host);
return; return;
} }
while (this === requests[0] && output.length > 0) { 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 () { 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(); requests[0].flush();
}; };
connection.onEOF = function () {
//node.debug("onEOF. readyState = " + connection.readyState);
connection.close();
};
connection.onDisconnect = function (had_error) { connection.onDisconnect = function (had_error) {
if (had_error) { if (had_error) {
if (self.onError) self.onError(); if (self.onError) self.onError();
return; return;
} }
//node.debug("HTTP CLIENT: disconnect"); //node.debug("HTTP CLIENT onDisconnect. readyState = " + connection.readyState);
// If there are more requests to handle, reconnect. // If there are more requests to handle, reconnect.
if (requests.length > 0) { if (requests.length > 0) {
//node.debug("HTTP CLIENT: reconnecting"); //node.debug("HTTP CLIENT: reconnecting");

3
src/net.cc

@ -185,13 +185,12 @@ Connection::Connect (const Arguments& args)
* http://lists.schmorp.de/pipermail/libev/2009q1/000632.html * http://lists.schmorp.de/pipermail/libev/2009q1/000632.html
*/ */
eio_warmup(); eio_warmup();
connection->Attach();
eio_custom( Connection::Resolve eio_custom( Connection::Resolve
, EIO_PRI_DEFAULT , EIO_PRI_DEFAULT
, Connection::AfterResolve , Connection::AfterResolve
, connection , connection
); );
connection->Attach();
return Undefined(); return Undefined();
} }

4
test_client.js

@ -21,8 +21,8 @@ req.finish(function (res) {
}); });
setTimeout(function () { setTimeout(function () {
var req2 = c.get("/something/else", []); var req2 = c.get("/something/else");
puts("start req2"); //node.debug("start req2");
req2.finish(function (res) { req2.finish(function (res) {
puts("response 2: " + res.statusCode.toString()); puts("response 2: " + res.statusCode.toString());

Loading…
Cancel
Save