Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header option bugs #197

Open
arthurfranca opened this issue Mar 6, 2020 · 1 comment
Open

Header option bugs #197

arthurfranca opened this issue Mar 6, 2020 · 1 comment

Comments

@arthurfranca
Copy link

Middleware localOptions.headers currently are ignored (only globalOptions.headers are used)

apicache/src/apicache.js

Lines 189 to 195 in f27cb2b

Object.keys(globalOptions.headers).forEach(function(name) {
res.setHeader(name, globalOptions.headers[name])
})
res.writeHead = function() {
// add cache control headers
if (!globalOptions.headers['cache-control']) {

Also, following code is ignoring the possibility of cacheObject.headers['cache-control'] being a value previously overrided by global/localOptions, like e.g. max-age=0, must-revalidate or no-cache or maybe a max-age lower than that being currently set.
I mean, if there was global/localOptions.headers['cache-control'] that was used when caching response, i think it should be used when sending cached response

apicache/src/apicache.js

Lines 251 to 259 in f27cb2b

Object.assign(headers, filterBlacklistedHeaders(cacheObject.headers || {}), {
// set properly-decremented max-age header. This ensures that max-age is in sync with the cache expiration.
'cache-control':
'max-age=' +
Math.max(
0,
(duration / 1000 - (new Date().getTime() / 1000 - cacheObject.timestamp)).toFixed(0)
),
})

@stjosh
Copy link

stjosh commented Mar 13, 2020

I think #163 tries to fix the same issue with not counting that 'cache-control' could already be set... This is really bugging me as well, as I do invalidate my cache on every write to the DB and don't want my clients to sit around with stale responses...

@kwhitley Any chance this could be fixed soon? I had to disable my cache again due to not being able to override the cache-control header...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants