add vary header to honor authorization header when caching

This commit is contained in:
Eneko Lakasta 2018-03-06 12:46:38 +01:00
parent 39bd6694f2
commit b0eacb2a79
2 changed files with 2 additions and 0 deletions

View File

@ -5,6 +5,7 @@ module.exports = function apikeyToken () {
const apikeyCredentials = getApikeyCredentialsFromRequest(req);
res.locals.api_key = apikeyCredentials.token;
res.locals.apikeyUsername = apikeyCredentials.username;
res.set('vary', 'Authorization'); //Honor Authorization header when caching.
return next();
};
};

View File

@ -155,6 +155,7 @@ describe('get requests with cache headers', function() {
assert.ok(res.headers['x-cache-channel']);
assert.ok(res.headers['surrogate-key']);
assert.ok(res.headers['vary'] === 'Authorization');
if (expectedCacheHeaders) {
validateXChannelHeaders(res.headers, expectedCacheHeaders);
assert.equal(res.headers['surrogate-key'], expectedCacheHeaders.surrogate_keys);