-
Notifications
You must be signed in to change notification settings - Fork 263
Set onion, vary and Link headers in Next.js app
#13547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
120 commits
Select commit
Hold shift + click to select a range
364bd31
Move `sw.js` rewrite to `next.config`
amoore108 b1ac65e
Update next.config.js
amoore108 c8e70e7
Logic to set headers from `_document`
amoore108 86b716f
Fix `tsc` error
amoore108 73a7cb7
Remove `middleware`
amoore108 da25265
Check hostname
amoore108 efffba4
Update _document.page.tsx
amoore108 1c90626
Update index.ts
amoore108 995bd14
Merge branch 'latest' into move-sw.js-rewrite-to-next.config
amoore108 0b6ff25
Merge branch 'latest' into move-sw.js-rewrite-to-next.config
amoore108 5c09c88
Merge branch 'latest' into move-sw.js-rewrite-to-next.config
amoore108 29abfc2
Replace `cspHeaderResponse` with `DocumentContext` version
amoore108 157e312
Fetch toggles from `_document.page.tsx`
amoore108 96d15ab
Pass args as object
amoore108 5d2c637
Add `extractHeaders` function to global page props
amoore108 3bfde8d
Pass `isNextJs: true` down
amoore108 6925ed3
Remove toggle check from `augmentWithDisclaimer`
amoore108 c112fa8
Remove `toggles` from `getServerSideProps` in pages
amoore108 e845825
Remove `toggles` fetch from `getPageData`
amoore108 e812071
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 659d870
Remove `toggles` from old article fetcher to fix TS error
amoore108 17b3974
fallback to `index` if no `id` on block
amoore108 576873c
Remove platform flags from `handleArticleRoute`
amoore108 70f9ffa
Remove platform flag from `handleAvRoute`
amoore108 2302978
Remove platform flags from `downloads` page
amoore108 8987c09
Remove platform flags from `live` page
amoore108 fe53045
Remove platform flags from `send` page
amoore108 e3b4173
Remove platform flag from `watch` page
amoore108 b58cfff
Remove platform flags from catch-all route
amoore108 b7ff18b
Remove platform flags from `wrapped` page
amoore108 6470eaf
Remove platform flags from `languages` page
amoore108 4dcc656
Remove unneeded import
amoore108 49ffb5d
Remove `extractHeaders` from articles route
amoore108 9abc415
Remove `extractHeaders` from av-embeds route
amoore108 f521257
Remove `extractHeaders` from downloads route
amoore108 898c0d3
Remove `extractHeaders` from live route
amoore108 6be2b70
Remove `extractHeaders` from send route
amoore108 a034805
Remove `extractHeaders` from watch route
amoore108 a750b0c
Remove `extractHeaders` from catch-all route
amoore108 4575d98
Remove `extractHeaders` from wrapped route
amoore108 fc981a2
Remove duplicate `ctx.res?.setHeader`
amoore108 1ad3a42
Move logic from _document and move to _app
amoore108 d7fa9eb
Fix type imports
amoore108 5910d7d
Remove `appProps` and add comment
amoore108 3f88c1b
Use cached version of toggles
amoore108 bdf3db0
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 71bfcc7
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 7ca7ecc
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 11bcf52
Rename CSP header tests to be more reflective of intent
amoore108 d264314
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 dcf3ade
Make toggles destruct more readable
amoore108 f771e72
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 094797c
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 0d51750
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 052b96c
Add `service` to toggles fetch from `ctx`
amoore108 1d92695
Pass `service` down to csp header function to simplify logic
amoore108 d1ee521
Move comment for clarity
amoore108 a35e982
Get `service` from path instead of `query`
amoore108 ac7487e
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 6a88bec
Update augmentWithDisclaimer.test.ts
amoore108 8d963eb
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 853616b
Remove toggles fetch and common props from Offline page
amoore108 9e582fd
Merge branch 'latest' into nextjs-toggles-refactor
amoore108 1af8546
Remove `async/await` from header setting
amoore108 6494cbb
Update _app.page.tsx
amoore108 74d3ad8
Add `Unknown` page type
amoore108 7665b57
Remove manual `Unknown` type unions
amoore108 7223ac5
Separate out header setting
amoore108 1bde009
Move csp header function call logic into cspHeaderResponse function
amoore108 bb24194
Fix tests
amoore108 d788d26
Rename folder
amoore108 68e731c
Move into separate utils folder
amoore108 b454b9c
Remove server experiments logic from articles route
amoore108 c79d1c7
add tests
amoore108 0df6419
Convert _app to class component to be consistent with _document
amoore108 0bf2aeb
Remove unneeded type cast
amoore108 aff87f0
Move `handleServerLogging` to separate file
amoore108 7217d92
Update _app.page.tsx
amoore108 4ec7c9b
Update _app.page.tsx
amoore108 bb3688a
Update _app.page.tsx
amoore108 a098527
Update _app.page.tsx
amoore108 f0d4683
Add page type tests to `derivePageType`
amoore108 24dfb60
Use `page-type` header first if available
amoore108 30973a7
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 dc117fd
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 6bc7e25
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 42c47bd
Fix import order
amoore108 698f3cc
Update _app.page.tsx
amoore108 5966ef7
Update _app.page.tsx
amoore108 da310b1
Update index.test.ts
amoore108 e894ff3
Convert _error page to class component
amoore108 49848a2
Update _error.page.tsx
amoore108 6214f51
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 2e18a04
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 cada129
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 dee6b14
Use `UNKNOWN_PAGE` const
amoore108 a7475a6
Mock url typo
amoore108 e855f90
Check localhost domain using `some`
amoore108 4d018e4
Change instances of `'unknown'` page type to use const
amoore108 1e822b3
Update _error.page.tsx
amoore108 4ccd313
Make type import consistent
amoore108 41f74f7
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 68e7da6
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 dc1eddd
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 3188751
un-pluralise vary header function
amoore108 94dd575
Add `Link` header function
amoore108 2e34c5f
Fix typo in process.env setting in test
amoore108 8082e92
Change `getAssetOrigins` to TS
amoore108 7321d43
Move consts out of function
amoore108 239fb04
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 4c2a0c1
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 d94f591
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 ff8a8ce
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 baa8fba
Update ws-nextjs-app/utilities/derivePageType/index.test.ts
amoore108 efcd806
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 14de2bd
Update responseHeaderTests.ts
amoore108 04b9534
typo
amoore108 ad04159
Extend `responseHeaderTests` integration tests
amoore108 d877e25
Update responseHeaderTests.ts
amoore108 0cb07f0
Merge branch 'latest' into set-vary-onion-headers-in-nextjs
amoore108 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
7 changes: 3 additions & 4 deletions
7
...server/utilities/getAssetOrigins/index.js → ...server/utilities/getAssetOrigins/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,39 @@ | ||
| export default () => { | ||
| // This header is set in the Next.js middleware/proxy file: 'ws-nextjs-app/middleware.ts' | ||
| // The presence of this header and its value including the word 'SIMORGH' indicates that middleware/proxy is working correctly | ||
| // These headers are set in the Next.js _app.page.tsx file | ||
| // The presence of this header and its value including the word 'SIMORGH' indicates that _app.page.tsx is setting headers correctly | ||
| describe('req-svc-chain is set correctly', () => { | ||
| it('should contain the correct svc chain', async () => { | ||
| const fetchResponse = await fetch(window.location.href); | ||
| const reqSvcChain = fetchResponse.headers.get('req-svc-chain'); | ||
| expect(reqSvcChain).toContain('SIMORGH'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Onion-Location header is set correctly', () => { | ||
| it('should contain the correct Onion-Location header', async () => { | ||
| const fetchResponse = await fetch(window.location.href); | ||
| const onionHeader = fetchResponse.headers.get('Onion-Location'); | ||
| expect(onionHeader).toBe( | ||
| `https://www.bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion${new URL(window.location.href).pathname}`, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Vary header is set correctly', () => { | ||
| it('should contain the correct Vary header', async () => { | ||
| const fetchResponse = await fetch(window.location.href); | ||
| const varyHeader = fetchResponse.headers.get('Vary'); | ||
| expect(varyHeader).toContain('X-Country, Accept-Encoding'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Link header is set correctly', () => { | ||
| it('should contain the correct Link header for AMP pages', async () => { | ||
| const fetchResponse = await fetch(window.location.href); | ||
| const linkHeader = fetchResponse.headers.get('Link'); | ||
| expect(linkHeader).toContain( | ||
| '<https://ichef.bbci.co.uk>; rel="dns-prefetch"', | ||
| ); | ||
| }); | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.