1
0
mirror of synced 2025-12-21 19:06:49 -05:00

set max-age=0 when you want no cache (#31657)

This commit is contained in:
Peter Bengtsson
2022-10-12 21:54:28 +02:00
committed by GitHub
parent 61b66543ad
commit 5dfca10bba
5 changed files with 16 additions and 10 deletions

View File

@@ -26,6 +26,7 @@ export function cacheControlFactory(
maxAge && immutable && 'immutable',
!maxAge && 'private',
!maxAge && 'no-store',
maxAge === 0 && 'max-age=0',
]
.filter(Boolean)
.join(', ')

View File

@@ -9,6 +9,7 @@ import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
import { getPathWithoutVersion } from '../../lib/path-utils.js'
import { describe, jest } from '@jest/globals'
const NO_CACHE_CONTROL = 'private, no-store, max-age=0'
const AZURE_STORAGE_URL = 'githubdocs.azureedge.net'
const activeProducts = Object.values(productMap).filter(
(product) => !product.wip && !product.hidden
@@ -606,7 +607,7 @@ describe('server', () => {
expect(res.statusCode).toBe(302)
expect(res.headers['set-cookie']).toBeUndefined()
// no cache control because a language prefix had to be injected
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
})
test('redirects old articles to their slugified URL', async () => {
@@ -620,7 +621,7 @@ describe('server', () => {
const res = await get('/')
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/en')
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
expect(res.headers['set-cookie']).toBeUndefined()
})
@@ -639,7 +640,7 @@ describe('server', () => {
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/en')
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
expect(res.headers['set-cookie']).toBeUndefined()
})
@@ -653,7 +654,7 @@ describe('server', () => {
})
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/en')
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
expect(res.headers['set-cookie']).toBeUndefined()
})
@@ -663,7 +664,7 @@ describe('server', () => {
expect(res.headers.location.startsWith('/en/')).toBe(true)
expect(res.headers['set-cookie']).toBeUndefined()
// no cache control because a language prefix had to be injected
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
})
test('redirects that not only injects /en/ should have cache-control', async () => {

View File

@@ -4,6 +4,8 @@ import enterpriseServerReleases from '../../lib/enterprise-server-releases.js'
import { get, getDOM } from '../helpers/e2etest.js'
import { SURROGATE_ENUMS } from '../../middleware/set-fastly-surrogate-key.js'
const NO_CACHE_CONTROL = 'private, no-store, max-age=0'
jest.useFakeTimers({ legacyFakeTimers: true })
describe('enterprise deprecation', () => {
@@ -96,7 +98,7 @@ describe('recently deprecated redirects', () => {
expect(res.headers.location).toBe('/en/enterprise-server@3.0')
expect(res.headers['set-cookie']).toBeUndefined()
// Deliberately no cache control because it is user-dependent
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
})
test('already languaged enterprise 3.0 redirects', async () => {
@@ -115,7 +117,7 @@ describe('recently deprecated redirects', () => {
expect(res.statusCode).toBe(302)
expect(res.headers['set-cookie']).toBeUndefined()
// Deliberately no cache control because it is user-dependent
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
// This is based on
// https://github.com/github/help-docs-archived-enterprise-versions/blob/master/3.0/redirects.json
expect(res.headers.location).toBe(

View File

@@ -126,7 +126,7 @@ describe('redirects', () => {
const res = await get('/')
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe('/en')
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe('private, no-store, max-age=0')
})
test('trailing slash on languaged homepage should permantently redirect', async () => {

View File

@@ -2,6 +2,8 @@ import { languageKeys } from '../../lib/languages.js'
import { get } from '../helpers/e2etest.js'
import { PREFERRED_LOCALE_COOKIE_NAME } from '../../lib/constants.js'
const NO_CACHE_CONTROL = 'private, no-store, max-age=0'
const langs = languageKeys.filter((lang) => lang !== 'en')
describe('redirects', () => {
@@ -12,7 +14,7 @@ describe('redirects', () => {
})
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe(`/${lang}/get-started`)
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
expect(res.headers['set-cookie']).toBeUndefined()
})
@@ -26,7 +28,7 @@ describe('redirects', () => {
})
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe(`/${lang}/get-started`)
expect(res.headers['cache-control']).toBe('private, no-store')
expect(res.headers['cache-control']).toBe(NO_CACHE_CONTROL)
expect(res.headers['set-cookie']).toBeUndefined()
})