expressjs / serve-static

Serve static files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Cache-Control: public, max-age=0" is set by default

SVasilev opened this issue · comments

Hello,
I am using this module for a while and I encountered the following problem. I cannot remove the Cache-Control header. It is always set by default to some value. I noticed that this behaviour comes from the "send" module, which you use:

if (!res.getHeader('Cache-Control')) {
  res.setHeader('Cache-Control', 'public, max-age=' + Math.floor(this._maxage / 1000));
}

I managed to make a work-around with the "on-headers" module, mentioned in issue #5 which looks like this:

var onHeaders = require('on-headers');
onHeaders(function() {
  this.removeHeader('Cache-Control');
}

But this approach looks pretty sketchy. So the question is why can't this be configured somewhere in the options, because after researching Apache and Nginx I saw that they don't add the Cache-Control header by default and I want to accomplish that behaviour. Besides it looks like the right approach to me because after looking at the HTTP1.1 spec I found:

Unless specifically constrained by a cache-control (section 14.9)
directive, a caching system MAY always store a successful response
(see section 13.8) as a cache entry, MAY return it without validation
if it is fresh, and MAY return it after successful validation.

So, it seems that is up to the Content Delivery Networks (Akamai, etc) to decide whether something is cachable by default. So is there a reason for forcing the Cache-Control by default in this module?

Hi @SVasilev, can you open an issue at https://github.com/pillarjs/send/issues? This module doesn't have any code actually setting the Cache-Control header, so though we can discuss here, we can't really resolve the issue here. We would like to have the discussion in the same repository that the code change would actually happen for future reference for ourselves and users, I hope you understand :)

Sorry, I didn't mean to close this issue, as we can keep it open while discussion happens in the send repository (so we can involve the jshttp group, who oversees the send module).

Hello,
Sorry for the late reply. I opened the issue as you told me:
pillarjs/send#110
Best regards,
Stefan