Removing all headers from express.js
Generally, you can use the API of the Response object in Express (node.js) to remove headers, however, some of them are required by the HTTP spec and should always be there.
The Date header is such a required one. See here: https://stackoverflow.com/a/14490432/1801
The first line (HTTP/1.1 200 OK
) is not a header - it is part of the HTTP protocol and each response should start with it. Otherwise the browser wouldn't know what to do with the response.
If you want to remove other custom headers, you can do it like this:
app.get('/test', function (req, res) {
var body = "some body";
res.removeHeader('Transfer-Encoding');
res.removeHeader('X-Powered-By');
res.end(body);
});
app.use(function (req, res, next) {
res.removeHeader("x-powered-by");
res.removeHeader("set-cookie");
res.removeHeader("Date");
res.removeHeader("Connection");
next();
});
For more details Please look into this doc for best way to explain all the http header related query:: Express (node.js) http header docs
Express isn't going to do this, since Express is for HTTP. What you have asked for is not HTTP, as it does not follow some of the RFCs. To do what you want, you would have to bypass express. Listen on the port, parse the GEt request from the embedded device, and send the data that you want.