Skip to content

Commit

Permalink
Merge pull request #337 from adobe/issue-336
Browse files Browse the repository at this point in the history
chore: set user agent header
  • Loading branch information
rofe committed May 3, 2023
2 parents 3062f55 + 723a6c7 commit be4d84b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,37 @@ function checkViewDocSource(id) {
});
}

/**
* Appends sidekick name and version to the user-agent header for all requests to
* admin.hlx.page and rum.hlx.page.
*/
async function setUserAgentHeader() {
// remove existing rule first
await chrome.declarativeNetRequest.updateDynamicRules({ removeRuleIds: [100] });
const manifest = chrome.runtime.getManifest();
await chrome.declarativeNetRequest.updateDynamicRules({
addRules: [
{
id: 100,
priority: 1,
action: {
type: 'modifyHeaders',
requestHeaders: [
{
operation: 'set',
header: 'user-agent',
value: `${navigator.userAgent} Sidekick/${manifest.version}`,
},
],
},
condition: {
requestDomains: ['admin.hlx.page', 'rum.hlx.page'],
},
},
],
});
}

/**
* Sets the x-auth-token header for all requests to admin.hlx.page if project config
* has an auth token.
Expand Down Expand Up @@ -408,6 +439,7 @@ async function storeAuthToken(owner, repo, token) {
log.info(`sidekick extension installed (${reason})`);
await updateHelpContent();
await updateProjectConfigs();
await setUserAgentHeader();
await updateAdminAuthHeaderRules();
});

Expand Down
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export function Nock() {
) => {
// nock stray rum requests
nocker('https://rum.hlx.page/')
.get(/.*/)
.post(/.*/)
.optionally()
.reply(200)
.persist();
Expand Down

0 comments on commit be4d84b

Please sign in to comment.