Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/dadi/cdn into patch/html…
Browse files Browse the repository at this point in the history
…-passthrough-tests
  • Loading branch information
jimlambie committed Oct 9, 2018
2 parents 0a164f5 + 8bc5de1 commit be137fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dadi/lib/controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Controller = function (router) {
this.addContentTypeHeader(res, handler)
this.addCacheControlHeader(res, handler, req.__domain)
this.addLastModifiedHeader(res, handler)
this.addVaryHeader(res, handler)

if (handler.storageHandler && handler.storageHandler.notFound) {
res.statusCode = config.get('notFound.statusCode', req.__domain) || 404
Expand Down Expand Up @@ -201,6 +202,12 @@ Controller.prototype.addLastModifiedHeader = function (res, handler) {
}
}

Controller.prototype.addVaryHeader = function (res, handler) {
if (!handler) return

res.setHeader('Vary', 'Accept-Encoding')
}

Controller.prototype.addCacheControlHeader = function (res, handler, domain) {
let configHeaderSets = config.get('headers.cacheControl', domain)

Expand Down
12 changes: 12 additions & 0 deletions test/acceptance/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ describe('Cache', function () {
})
})

it('should return a vary accept encoding header', done => {
client
.get('/test.jpg')
.expect(200)
.end((err, res) => {
if (err) return done(err)

res.headers['vary'].should.eql('Accept-Encoding')
done()
})
})

describe('caching 404 responses', () => {
it('should not cache a 404 if caching.cache404 is false and the image fallback is disabled', done => {
config.set('caching.cache404', false)
Expand Down

0 comments on commit be137fe

Please sign in to comment.