I'm sending requests from NodeJs to legacy server, which uses HTTP/0.9. Response comes and throws an error: Parse Error. Couldn't find anything in docs about HTTP protocol support. Am I doing something wrong or NodeJS doesn't support HTTP/0.9?
Node does not support HTTP/0.9 not only because it's hardly in use anymore, but because real HTTP/0.9 responses just consist of response data. That means that there is no status line indicating the response's HTTP version, so there is no way to differentiate an HTTP/0.9 response from either a malformed HTTP/1.x response or even an HTTP/0.9 response that starts with the string "HTTP/1.1 200 OK\r\n".
A way to hack around it, assuming you use linux, is to use a child process with curl. Here is a code example, applied on a URL pointing to an old Shoutcast server.;
var URL = "http://streaming3.radiocat.net/;";
// This will fail because HTTP 0.9 is not supported by Node.
var http = require("http");
var url = require("url");
http.get(url.parse(URL), function (res) {
res.on("data", function(data) {
console.log(data);
});
});
// This will work
var cp = require('child_process');
var request = cp.spawn("curl", ["-L", URL], { stdio: ['pipe', 'pipe', process.stderr] });
request.stdout.on("data", function(data) {
console.log(data);
});
/* Detail of the http.get error:
events.js:182
throw er; // Unhandled 'error' event
^
Error: Parse Error
at Socket.socketOnData (_http_client.js:454:20)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:266:12)
at readableAddChunk (_stream_readable.js:253:11)
at Socket.Readable.push (_stream_readable.js:211:10)
at TCP.onread (net.js:585:20)
*/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With