[nodejs] Closed Connection Does Not Trigger httpClient.response "end" event

84 views
Skip to first unread message

Tautologistics

unread,
May 5, 2010, 9:38:54 AM5/5/10
to nodejs
Just an FYI about this quirk I just encountered. I close the
connection is the server response is bigger than I want but was not
getting an "end" event on the response. Here's the workaround:

request.addListener('response', function (response) {
sys.debug("RESPONSE");

response.setEncoding('utf8');
var responseAborted = false;
var contentLength = response.headers["content-length"] || 0;
function abort () {
if (!responseAborted) {
response.connection.addListener("close", function () {
sys.debug("CLOSE");
response.emit("end", true);
});
responseAborted = true;
response.connection.end();
}
}

if (contentLength > 1024) {
abort();
} else {
var contentLengthRecv = 0;
response.addListener('data', function (chunk) {
contentLengthRecv += chunk.length;
sys.debug("DATA " + contentLength + ":" + contentLengthRecv);
if (contentLengthRecv > 1024) {
abort();
}
});
}
response.addListener('end', function (forceClosed) {
sys.debug("END");
});
});
request.end();

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

Tom

unread,
Nov 6, 2012, 3:13:21 AM11/6/12
to nod...@googlegroups.com
This still hasn't been fixed. Any news on the situation?

Op woensdag 5 mei 2010 20:38:54 UTC+7 schreef Tautologistics het volgende:

Tom

unread,
Jan 21, 2013, 12:18:59 PM1/21/13
to nod...@googlegroups.com
Still no updates on the matter?
Reply all
Reply to author
Forward
0 new messages