send s-maxage cache header (#5046)
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
This commit is contained in:
@@ -69,7 +69,7 @@ function setHeadersForCacheLength(res, cacheLengthSeconds) {
|
||||
cacheControl = 'no-cache, no-store, must-revalidate'
|
||||
expires = nowGMTString
|
||||
} else {
|
||||
cacheControl = `max-age=${cacheLengthSeconds}`
|
||||
cacheControl = `max-age=${cacheLengthSeconds} s-maxage=${cacheLengthSeconds}`
|
||||
expires = new Date(now.getTime() + cacheLengthSeconds * 1000).toGMTString()
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ function setCacheHeaders({
|
||||
setHeadersForCacheLength(res, cacheLengthSeconds)
|
||||
}
|
||||
|
||||
const staticCacheControlHeader = `max-age=${24 * 3600}` // 1 day.
|
||||
const staticCacheControlHeader = `max-age=${24 * 3600} s-maxage=${24 * 3600}` // 1 day.
|
||||
function setCacheHeadersForStaticResource(res) {
|
||||
res.setHeader('Cache-Control', staticCacheControlHeader)
|
||||
res.setHeader('Last-Modified', serverStartTimeGMTString)
|
||||
|
||||
@@ -146,7 +146,9 @@ describe('Cache header functions', function() {
|
||||
})
|
||||
|
||||
it('should set the expected Cache-Control header', function() {
|
||||
expect(res._headers['cache-control']).to.equal('max-age=123')
|
||||
expect(res._headers['cache-control']).to.equal(
|
||||
'max-age=123 s-maxage=123'
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the expected Expires header', function() {
|
||||
@@ -184,7 +186,9 @@ describe('Cache header functions', function() {
|
||||
})
|
||||
|
||||
it('should set the expected Cache-Control header', function() {
|
||||
expect(res._headers['cache-control']).to.equal(`max-age=${24 * 3600}`)
|
||||
expect(res._headers['cache-control']).to.equal(
|
||||
`max-age=${24 * 3600} s-maxage=${24 * 3600}`
|
||||
)
|
||||
})
|
||||
|
||||
it('should set the expected Last-Modified header', function() {
|
||||
|
||||
@@ -254,7 +254,7 @@ describe('The request handler', function() {
|
||||
+new Date(headers.date) + 900000
|
||||
).toGMTString()
|
||||
expect(headers.expires).to.equal(expectedExpiry)
|
||||
expect(headers['cache-control']).to.equal('max-age=900')
|
||||
expect(headers['cache-control']).to.equal('max-age=900 s-maxage=900')
|
||||
})
|
||||
|
||||
it('should set the expected cache headers on cached responses', async function() {
|
||||
@@ -268,7 +268,7 @@ describe('The request handler', function() {
|
||||
+new Date(headers.date) + 900000
|
||||
).toGMTString()
|
||||
expect(headers.expires).to.equal(expectedExpiry)
|
||||
expect(headers['cache-control']).to.equal('max-age=900')
|
||||
expect(headers['cache-control']).to.equal('max-age=900 s-maxage=900')
|
||||
})
|
||||
|
||||
it('should let live service data override the default cache headers with longer value', async function() {
|
||||
@@ -289,7 +289,7 @@ describe('The request handler', function() {
|
||||
)
|
||||
|
||||
const { headers } = await got(`${baseUrl}/testing/123.json`)
|
||||
expect(headers['cache-control']).to.equal('max-age=400')
|
||||
expect(headers['cache-control']).to.equal('max-age=400 s-maxage=400')
|
||||
})
|
||||
|
||||
it('should not let live service data override the default cache headers with shorter value', async function() {
|
||||
@@ -310,7 +310,7 @@ describe('The request handler', function() {
|
||||
)
|
||||
|
||||
const { headers } = await got(`${baseUrl}/testing/123.json`)
|
||||
expect(headers['cache-control']).to.equal('max-age=300')
|
||||
expect(headers['cache-control']).to.equal('max-age=300 s-maxage=300')
|
||||
})
|
||||
|
||||
it('should set the expires header to current time + cacheSeconds', async function() {
|
||||
@@ -322,7 +322,7 @@ describe('The request handler', function() {
|
||||
+new Date(headers.date) + 3600000
|
||||
).toGMTString()
|
||||
expect(headers.expires).to.equal(expectedExpiry)
|
||||
expect(headers['cache-control']).to.equal('max-age=3600')
|
||||
expect(headers['cache-control']).to.equal('max-age=3600 s-maxage=3600')
|
||||
})
|
||||
|
||||
it('should ignore cacheSeconds when shorter than defaultCacheLengthSeconds', async function() {
|
||||
@@ -334,7 +334,7 @@ describe('The request handler', function() {
|
||||
+new Date(headers.date) + 600000
|
||||
).toGMTString()
|
||||
expect(headers.expires).to.equal(expectedExpiry)
|
||||
expect(headers['cache-control']).to.equal('max-age=600')
|
||||
expect(headers['cache-control']).to.equal('max-age=600 s-maxage=600')
|
||||
})
|
||||
|
||||
it('should set Cache-Control: no-cache, no-store, must-revalidate if cache seconds is 0', async function() {
|
||||
|
||||
Reference in New Issue
Block a user