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 nodejs@googlegroups.com.
To unsubscribe from this group, send email to nodejs+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.