MCPcopy
hub / github.com/github/docs / checkCachingHeaders

Function checkCachingHeaders

tests/helpers/caching-headers.js:3–14  ·  view source on GitHub ↗
(res, defaultSurrogateKey = false, minMaxAge = 60 * 60)

Source from the content-addressed store, hash-verified

1import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
2
3export function checkCachingHeaders(res, defaultSurrogateKey = false, minMaxAge = 60 * 60) {
4 expect(res.headers['set-cookie']).toBeUndefined()
5 expect(res.headers['cache-control']).toContain('public')
6 const maxAgeSeconds = parseInt(res.headers['cache-control'].match(/max-age=(\d+)/)[1], 10)
7 // Let's not be too specific in the tests, just as long as it's testing
8 // that it's a reasonably large number of seconds.
9 expect(maxAgeSeconds).toBeGreaterThanOrEqual(minMaxAge)
10 // Because it doesn't have have a unique URL
11 expect(res.headers['surrogate-key'].split(/\s/g)[0]).toBe(
12 defaultSurrogateKey ? SURROGATE_ENUMS.DEFAULT : SURROGATE_ENUMS.MANUAL
13 )
14}

Callers 2

static-assets.jsFile · 0.90
static-assets.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected