I am creating a page where I have some data that gets parsed by another device. I used to do this with php but I am moving it to node. I need to remove any and all headers from the page so I only have my output. This output is a response to a GET request.
At the moment I have
HTTP/1.1 200 OK
Date: Wed, 11 Sep 2013 11:54:14 GMT
Connection: close
My output
I need it to just display
My output
removeHeader() (Added in v0. 9.3) property is an inbuilt property of the 'http' module which removes a header identified by a name that's queued for implicit sending.
Guidelines. The dp:remove-http-request-header function removes a specific header field and its associated value from the protocol header of a client request. If the client request contains the header field that is identified by the name parameter, the function removes this header field from the client request.
It is unmaintained Express has not been updated for years, and its next version has been in alpha for 6 years. People may think it is not updated because the API is stable and does not need change. The reality is: Express does not know how to handle async/await .
The header tells the server details about the request such as what type of data the client, user, or request wants in the response. Type can be html , text , JSON , cookies or others.
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
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);
});
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