Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/server/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,16 @@ server.get(
isAmp,
});

const { isUK, showCookieBannerBasedOnCountry } = extractHeaders(headers);
const { isUK, showCookieBannerBasedOnCountry, ECT } =
extractHeaders(headers);

data.toggles = toggles;
data.path = urlPath;
data.timeOnServer = Date.now();
data.showAdsBasedOnLocation = headers['bbc-adverts'] === 'true';
data.showCookieBannerBasedOnCountry = showCookieBannerBasedOnCountry;
data.isUK = isUK;
data.isLite = isLite;
data.isLite = isLite || ['slow-2g', '2g', '3g'].includes(ECT);

let { status } = data;
// Set derivedPageType based on returned page data
Expand Down Expand Up @@ -346,8 +347,11 @@ server.get(
'onion-location',
`https://www.bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion${urlPath}`,
);
const clientHints = 'ECT';
res.set('accept-ch', clientHints);
res.set('critical-ch', clientHints);

const allVaryHeaders = ['X-Country'];
const allVaryHeaders = ['X-Country', ...clientHints.split(',')];
const mvtVaryHeaders = !isAmp && getMvtVaryHeaders(mvtExperiments);
if (mvtVaryHeaders) allVaryHeaders.push(mvtVaryHeaders);

Expand Down
6 changes: 3 additions & 3 deletions src/server/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,7 @@ describe('Server HTTP Headers - Page Endpoints', () => {
const { header } = await makeRequest('/mundo/c0000000001o');

expect(header.vary).toBe(
'X-Country, mvt-simorgh_dark_mode, Accept-Encoding',
'X-Country, ECT, mvt-simorgh_dark_mode, Accept-Encoding',
);
});

Expand All @@ -1554,7 +1554,7 @@ describe('Server HTTP Headers - Page Endpoints', () => {

const { header } = await makeRequest('/mundo/articles/c0000000001o');

expect(header.vary).toBe('X-Country, Accept-Encoding');
expect(header.vary).toBe('X-Country, ECT, Accept-Encoding');
});

it(`should not add mvt experiment header names to vary if on AMP`, async () => {
Expand All @@ -1566,7 +1566,7 @@ describe('Server HTTP Headers - Page Endpoints', () => {

const { header } = await makeRequest('/mundo/articles/c0000000001o');

expect(header.vary).toBe('X-Country, Accept-Encoding');
expect(header.vary).toBe('X-Country, ECT, Accept-Encoding');
});

it(`should set isUK value to true when 'x-bbc-edge-isuk' is set to 'yes'`, async () => {
Expand Down
20 changes: 20 additions & 0 deletions src/server/utilities/extractHeaders/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('extractHeader', () => {
'x-bbc-edge-isuk': 'yes',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: null,
isUK: true,
showAdsBasedOnLocation: false,
Expand All @@ -18,6 +19,7 @@ describe('extractHeader', () => {
'x-country': 'gb',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: null,
isUK: true,
showAdsBasedOnLocation: false,
Expand All @@ -31,6 +33,7 @@ describe('extractHeader', () => {
'x-bbc-edge-isuk': 'no',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: null,
isUK: false,
showAdsBasedOnLocation: false,
Expand All @@ -44,6 +47,7 @@ describe('extractHeader', () => {
'x-bbc-edge-isuk': 'yes',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: null,
isUK: true,
showAdsBasedOnLocation: false,
Expand All @@ -56,6 +60,7 @@ describe('extractHeader', () => {
'x-bbc-edge-country': 'za',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: null,
isUK: null,
showAdsBasedOnLocation: false,
Expand All @@ -68,6 +73,7 @@ describe('extractHeader', () => {
'bbc-adverts': 'true',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: null,
isUK: null,
showAdsBasedOnLocation: true,
Expand All @@ -80,10 +86,24 @@ describe('extractHeader', () => {
'bbc-origin': 'https://www.bbc.co.uk/news',
});
expect(actual).toStrictEqual({
ECT: '4g',
bbcOrigin: 'https://www.bbc.co.uk/news',
isUK: null,
showAdsBasedOnLocation: false,
showCookieBannerBasedOnCountry: true,
});
});

it(`sets ECT when 'ECT' header is set`, () => {
const actual = extractHeaders({
ect: '2g',
});
expect(actual).toStrictEqual({
ECT: '2g',
bbcOrigin: null,
isUK: null,
showAdsBasedOnLocation: false,
showCookieBannerBasedOnCountry: true,
});
});
});
1 change: 1 addition & 0 deletions src/server/utilities/extractHeaders/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const extractHeaders = (headers: IncomingHttpHeaders) => {
isUK,
showAdsBasedOnLocation: headers['bbc-adverts'] === 'true' || false,
showCookieBannerBasedOnCountry,
ECT: headers.ect || '4g',
};
};

Expand Down
Loading