We have a need to remove the etag
header from all HTTP responses in our Node.js Express application. We have a web services API written in Express where unexpected results are seen at the client when we send etags and the client sends back the if-none-match
header.
We've tried app.disable('etag')
and res.removeHeader('etag')
, but neither work; the app sends the header regardless.
Is there any other means of disabling this header in all responses?
ETag value is nothing crazy, but a non-reversible, short, and fast hashed value of the Response Data (body). Server sends ETag header in Response to Client. Client sends if-none-matched header (with its value being previously received Etag values from server) in Request to Server.
An ETag (entity tag) is an HTTP header that is used to validate that the client (such as a mobile device) has the most recent version of a record. When a GET request is made, the ETag is returned as a response header. The ETag also allows the client to make conditional requests.
app.disable('etag')
should work now, there has been a pull request merged to deal with this:
https://github.com/visionmedia/express/commit/610e172fcf9306bd5812bb2bae8904c23e0e8043
UPDATE: as Bigood pointed out in the comments the new way of doing things is the following
app.set('etag', false); // turn off
Change occured with version 3.9.0: https://github.com/strongloop/express/releases/tag/3.9.0
For more options on setting the etag check the 4.x docs here: http://expressjs.com/4x/api.html#app.set
app.disable('etag')
This will disable etag header for all requests, but not for static contents. The following does it for static content:
app.use(express.static(path.join(__dirname, 'public'), { etag: false }));
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