Skip to content
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

spike: change response based on client hints #12549

Draft
wants to merge 7 commits into
base: latest
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
FIX: lint and change header from downlink to ECT
eagerterrier committed Mar 24, 2025

Verified

This commit was signed with the committer’s verified signature.
karinathomasbbc Karina Thomas
commit 7e3ec9f48374a0836a15c38f3c370a2a72e4bfb1
8 changes: 5 additions & 3 deletions src/server/index.jsx
Original file line number Diff line number Diff line change
@@ -244,15 +244,17 @@ server.get(
isAmp,
});

const { isUK, showCookieBannerBasedOnCountry, Downlink, DeviceMemory } = extractHeaders(headers);
const { isUK, showCookieBannerBasedOnCountry, ECT, DeviceMemory } =
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 || Downlink < 2 || DeviceMemory < 1;
data.isLite =
isLite || ['slow-2g', '2g', '3g'].includes(ECT) || DeviceMemory < 1;

let { status } = data;
// Set derivedPageType based on returned page data
@@ -340,7 +342,7 @@ server.get(
'onion-location',
`https://www.bbcweb3hytmzhn5d532owbu6oqadra5z3ar726vq5kgwwn6aucdccrad.onion${urlPath}`,
);
const clientHints = 'Downlink,Device-Memory';
const clientHints = 'ECT,Device-Memory';
res.set('accept-ch', clientHints);

const allVaryHeaders = ['X-Country', ...clientHints.split(',')];
2 changes: 1 addition & 1 deletion src/server/utilities/extractHeaders/index.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ const extractHeaders = (headers: IncomingHttpHeaders) => {
isUK,
showAdsBasedOnLocation: headers['bbc-adverts'] === 'true' || false,
showCookieBannerBasedOnCountry,
Downlink: headers['downlink'] || 100000,
ECT: headers.ect || '3g',
DeviceMemory: headers['device-memory'] || 8,
};
};

Unchanged files with check annotations Beta

const url = new URL(atiAnalyticsURL);
const objectFromEntries = Object.fromEntries(new URLSearchParams(url.search));
console.log(

Check warning on line 7 in cypress/e2e/specialFeatures/atiAnalytics/helpers/index.js

GitHub Actions / build (22.x)

Unexpected console statement
'objectFromEntries p value in getATIParamsFromURL',
objectFromEntries.p,
);