Skip to content

Commit bcc0d5b

Browse files
authored
Merge pull request #12598 from github/repo-sync
repo sync
2 parents dc89a16 + ddd1447 commit bcc0d5b

33 files changed

Lines changed: 356 additions & 247 deletions

middleware/cache-control.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
// cacheControlYear(res)
99
// res.send(body)
1010
//
11+
// Or, if you want to make it definitely not cache:
12+
//
13+
// const noCacheControl = getCacheControl(0) // you can use `false` too
14+
// ...
15+
// noControlYear(res)
16+
// res.send(body)
17+
//
1118
export function cacheControlFactory(maxAge = 60 * 60, public_ = true) {
12-
return (res) => res.set('cache-control', `${public_ ? 'public, ' : ''}max-age=${maxAge}`)
19+
return (res) => {
20+
if (maxAge) {
21+
res.set('cache-control', `${public_ ? 'public, ' : ''}max-age=${maxAge}`)
22+
} else {
23+
res.set('cache-control', 'private, no-store')
24+
}
25+
}
1326
}

middleware/redirects/handle-redirects.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import patterns from '../../lib/patterns.js'
22
import { URL } from 'url'
3-
import languages from '../../lib/languages.js'
3+
import languages, { languageKeys } from '../../lib/languages.js'
4+
import { cacheControlFactory } from '../cache-control.js'
5+
6+
const cacheControl = cacheControlFactory(60 * 60 * 24) // one day
7+
const noCacheControl = cacheControlFactory(0)
8+
9+
const languagePrefixURIRegex = new RegExp(`^/(${languageKeys.join('|')})/`)
410

511
export default function handleRedirects(req, res, next) {
612
// never redirect assets
@@ -19,7 +25,7 @@ export default function handleRedirects(req, res, next) {
1925
language = req.context.userLanguage
2026
}
2127

22-
res.set('cache-control', 'private, no-store')
28+
noCacheControl(res)
2329
return res.redirect(302, `/${language}`)
2430
}
2531

@@ -63,7 +69,11 @@ export default function handleRedirects(req, res, next) {
6369
return next()
6470
}
6571

66-
// do the redirect!
72+
// do the redirect if the from-URL already had a language in it
73+
if (languagePrefixURIRegex.test(req.path)) {
74+
cacheControl(res)
75+
}
76+
6777
return res.redirect(301, redirect)
6878
}
6979

tests/rendering/server.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,8 @@ describe('server', () => {
609609
test('redirects old articles to their English URL', async () => {
610610
const res = await get('/articles/deleting-a-team')
611611
expect(res.statusCode).toBe(301)
612+
// no cache control because a language prefix had to be injected
613+
expect(res.headers['cache-control']).toBeUndefined()
612614
})
613615

614616
test('redirects old articles to their slugified URL', async () => {
@@ -629,12 +631,21 @@ describe('server', () => {
629631
const res = await get('/articles/deleting-a-team')
630632
expect(res.statusCode).toBe(301)
631633
expect(res.headers.location.startsWith('/en/')).toBe(true)
634+
expect(res.headers['cache-control']).toBeUndefined()
635+
})
636+
637+
test('redirects that not only injects /en/ should have cache-control', async () => {
638+
const res = await get('/en/articles/deleting-a-team')
639+
expect(res.statusCode).toBe(301)
640+
expect(res.headers['cache-control']).toContain('public')
641+
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
632642
})
633643

634644
test('redirects Desktop Classic paths to desktop.github.com', async () => {
635645
const res = await get('/desktop-classic')
636646
expect(res.statusCode).toBe(301)
637647
expect(res.headers.location).toBe('https://desktop.github.com')
648+
expect(res.headers['cache-control']).toBeUndefined()
638649
})
639650

640651
// this oneoff redirect is temporarily disabled because it introduces too much complexity
@@ -646,6 +657,8 @@ describe('server', () => {
646657
expect(res.headers.location).toBe(
647658
'/en/github/managing-subscriptions-and-notifications-on-github'
648659
)
660+
expect(res.headers['cache-control']).toContain('public')
661+
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
649662
})
650663
})
651664

translations/log/pt-resets.csv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ translations/pt-BR/content/actions/automating-builds-and-tests/building-and-test
1111
translations/pt-BR/content/actions/automating-builds-and-tests/building-and-testing-python.md,rendering error
1212
translations/pt-BR/content/actions/creating-actions/creating-a-javascript-action.md,rendering error
1313
translations/pt-BR/content/actions/creating-actions/metadata-syntax-for-github-actions.md,rendering error
14+
translations/pt-BR/content/actions/creating-actions/releasing-and-maintaining-actions.md,rendering error
1415
translations/pt-BR/content/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services.md,rendering error
1516
translations/pt-BR/content/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-azure.md,rendering error
1617
translations/pt-BR/content/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-google-cloud-platform.md,rendering error
1718
translations/pt-BR/content/actions/deployment/security-hardening-your-deployments/using-openid-connect-with-reusable-workflows.md,rendering error
19+
translations/pt-BR/content/actions/deployment/targeting-different-environments/using-environments-for-deployment.md,rendering error
1820
translations/pt-BR/content/actions/guides.md,rendering error
1921
translations/pt-BR/content/actions/hosting-your-own-runners/about-self-hosted-runners.md,rendering error
2022
translations/pt-BR/content/actions/hosting-your-own-runners/adding-self-hosted-runners.md,Listed in localization-support#489
2123
translations/pt-BR/content/actions/hosting-your-own-runners/adding-self-hosted-runners.md,rendering error
24+
translations/pt-BR/content/actions/hosting-your-own-runners/managing-access-to-self-hosted-runners-using-groups.md,rendering error
2225
translations/pt-BR/content/actions/hosting-your-own-runners/monitoring-and-troubleshooting-self-hosted-runners.md,rendering error
2326
translations/pt-BR/content/actions/hosting-your-own-runners/removing-self-hosted-runners.md,rendering error
2427
translations/pt-BR/content/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners.md,rendering error
@@ -96,8 +99,10 @@ translations/pt-BR/content/code-security/code-scanning/integrating-with-code-sca
9699
translations/pt-BR/content/code-security/code-scanning/integrating-with-code-scanning/uploading-a-sarif-file-to-github.md,rendering error
97100
translations/pt-BR/content/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system.md,rendering error
98101
translations/pt-BR/content/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-runner-in-your-ci-system.md,rendering error
102+
translations/pt-BR/content/code-security/guides.md,rendering error
99103
translations/pt-BR/content/code-security/secret-scanning/about-secret-scanning.md,rendering error
100104
translations/pt-BR/content/code-security/secret-scanning/defining-custom-patterns-for-secret-scanning.md,rendering error
105+
translations/pt-BR/content/code-security/secret-scanning/managing-alerts-from-secret-scanning.md,rendering error
101106
translations/pt-BR/content/code-security/security-overview/about-the-security-overview.md,rendering error
102107
translations/pt-BR/content/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/automating-dependabot-with-github-actions.md,rendering error
103108
translations/pt-BR/content/code-security/supply-chain-security/managing-vulnerabilities-in-your-projects-dependencies/about-alerts-for-vulnerable-dependencies.md,rendering error
@@ -123,6 +128,7 @@ translations/pt-BR/content/codespaces/developing-in-codespaces/index.md,renderin
123128
translations/pt-BR/content/codespaces/developing-in-codespaces/using-codespaces-in-visual-studio-code.md,rendering error
124129
translations/pt-BR/content/codespaces/developing-in-codespaces/using-source-control-in-your-codespace.md,rendering error
125130
translations/pt-BR/content/codespaces/getting-started/deep-dive.md,rendering error
131+
translations/pt-BR/content/codespaces/guides.md,rendering error
126132
translations/pt-BR/content/codespaces/managing-codespaces-for-your-organization/enabling-codespaces-for-your-organization.md,rendering error
127133
translations/pt-BR/content/codespaces/managing-codespaces-for-your-organization/managing-billing-for-codespaces-in-your-organization.md,rendering error
128134
translations/pt-BR/content/codespaces/managing-codespaces-for-your-organization/managing-repository-access-for-your-organizations-codespaces.md,rendering error
@@ -198,6 +204,7 @@ translations/pt-BR/content/github/writing-on-github/working-with-advanced-format
198204
translations/pt-BR/content/github/writing-on-github/working-with-advanced-formatting/organizing-information-with-collapsed-sections.md,rendering error
199205
translations/pt-BR/content/graphql/guides/index.md,rendering error
200206
translations/pt-BR/content/graphql/guides/migrating-graphql-global-node-ids.md,rendering error
207+
translations/pt-BR/content/issues/guides.md,rendering error
201208
translations/pt-BR/content/issues/trying-out-the-new-projects-experience/customizing-your-project-views.md,rendering error
202209
translations/pt-BR/content/issues/trying-out-the-new-projects-experience/managing-access-to-projects.md,rendering error
203210
translations/pt-BR/content/organizations/keeping-your-organization-secure/reviewing-the-audit-log-for-your-organization.md,Listed in localization-support#489
@@ -267,6 +274,7 @@ translations/pt-BR/content/search-github/searching-on-github/searching-commits.m
267274
translations/pt-BR/content/search-github/searching-on-github/searching-discussions.md,rendering error
268275
translations/pt-BR/content/search-github/searching-on-github/searching-for-repositories.md,rendering error
269276
translations/pt-BR/content/search-github/searching-on-github/searching-issues-and-pull-requests.md,rendering error
277+
translations/pt-BR/content/sponsors/guides.md,rendering error
270278
translations/pt-BR/data/release-notes/enterprise-server/2-20/15.yml,Listed in localization-support#489
271279
translations/pt-BR/data/release-notes/enterprise-server/2-21/6.yml,Listed in localization-support#489
272280
translations/pt-BR/data/reusables/apps/deprecating_auth_with_query_parameters.md,Listed in localization-support#489

0 commit comments

Comments
 (0)