I need to receive requests in Node JS that almost identical to HTTP requests, but have a different word to HTTP in the header for example the first line of the request is:
POST / RTSP/1.0
(instead of POST / HTTP/1.0
)
The rest of the request format is identical to HTTP in every way.
Is there a way of making the http server parser ignore that the protocol is called HTTP in the first line of the request? So I can use http.createServer etc to receive and respond to these "non-HTTP" requests?
(I know I could use the net module rather than the http module, but then I'd have to implement the header parsing etc, all myself. )
Simplest way would be to implement tcp server in node that acts as a proxy replacing initial POST:
( note: I haven't tested this code, but it should be good enough to illustrate idea)
var net = require('net');
net.createServer(function(s)
{
var sawRequest = false;
var buff = "";
var requestText = "";
var connected = false;
var cli = net.createConnection(yourHttpServerPort);
s.on('data', function(d) {
if (!sawRequest) {
requestText += d.toString();
if (requestText.match(/POST \/ RTSP\/1.0/)) {
requestText.replace('POST / RTSP/1.0', 'POST / HTTP/1.0');
buff = requestText;
sawRequest = true;
}
} else {
buff += d.toString();
}
if (connected)
{
if (buff != '')
cli.write(buff);
cli.write(d);
} else {
buff += d.toString();
}
});
cli.once('connect', function() {
connected = true;
cli.write(buff);
});
cli.pipe(s);
}).listen(publicFacingRTSPport);
You could probably do the same with HAProxy