I'm working on an RSS aggregator via node-webkit, and I've stumbled upon an issue where a seemingly random volume of my requests (code below) will fail with any of the following errors: HPE_INVALID_CONSTANT, ETIMEDOUT, EAGAIN, and HPE_INVALID_HEADER_TOKEN. I've sorted those in regularity of occurrence.
I made a test.html file with as much relevance as possible. Just plug in a large volume of web page urls into httpList
and it will work. though, be careful what URLs you use, you wouldn't want to crash someones server! A list of around 56 seems to work for causing the errors.
As an aside, this is really hard to reproduce, meaning its gotta be something I can change on my end. Sometimes the same URL will fail, while on the next pass it will work. Also I have had URLs that have failed, that were indeed accessible (I opened them up in chrome no problem).
<!DOCTYPE html>
<html>
<head>
<title>HTTP Get test</title>
</head>
<body>
<script>
var httpList = [];
var fromUrl = function(stringUrl) {
var http = require('http');
var url = require("url");
var urlData = url.parse(stringUrl);
var parser = window.document.createElement('a');
parser.href = stringUrl;
var options = {
host: urlData.host,
path: urlData.path + urlData.search + urlData.hash
};
var httpResponse = function(response) {
response.setEncoding('utf8');
request.setSocketKeepAlive(true);
var str = '';
response.on('data', function(chunk) {
str += chunk;
});
response.on('end', function() {
request.setSocketKeepAlive(false);
console.log("url",stringUrl,"was successfully parsed");
});
}
var request = http.request(options, httpResponse)
request.on('error', function(e) {
if (e.code === "ENOTFOUND") {
console.error("The feed", stringUrl, "could not be fetched.")
} else {
console.log(e, e.message, stringUrl);
}
});
request.end();
};
for(var i=0;i<httpList.length;i++) {
fromUrl(httpList[i]);
}
</script>
</body>
</html>