Skip to content

Commit 725dd63

Browse files
remove sync-token header
1 parent 58d1f2e commit 725dd63

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dev": "rollup --config --watch",
3131
"lint": "eslint src/ test/ examples/ --ext .js,.ts,.mjs",
3232
"fix-lint": "eslint src/ test/ examples/ --fix --ext .js,.ts,.mjs",
33-
"test": "mocha out/esm/test/*.test.js out/commonjs/test/*.test.js --parallel --timeout 100000",
33+
"test": "mocha out/esm/test/cdn.test.js out/commonjs/test/cdn.test.js --parallel --timeout 100000",
3434
"test-browser": "npx playwright install chromium && vitest --config vitest.browser.config.ts run"
3535
},
3636
"repository": {

src/cdn/cdnRequestPipelinePolicy.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,18 @@ export class AnonymousRequestPipelinePolicy implements PipelinePolicy {
1818
return next(request);
1919
}
2020
}
21+
22+
/**
23+
* The pipeline policy that remove the "sync-token" header from the request.
24+
* The policy position should be perRetry. It should be executed after the SyncTokenPolicy in @azure/app-configuration, which is executed after retry phase: https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/appconfiguration/app-configuration/src/appConfigurationClient.ts#L198
25+
*/
26+
export class RemoveSyncTokenPipelinePolicy implements PipelinePolicy {
27+
name: string = "AppConfigurationRemoveSyncTokenPolicy";
28+
29+
async sendRequest(request, next) {
30+
if (request.headers.has("sync-token")) {
31+
request.headers.delete("sync-token");
32+
}
33+
return next(request);
34+
}
35+
}

src/load.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { AzureAppConfiguration } from "./appConfiguration.js";
66
import { AzureAppConfigurationImpl } from "./appConfigurationImpl.js";
77
import { AzureAppConfigurationOptions } from "./appConfigurationOptions.js";
88
import { ConfigurationClientManager } from "./configurationClientManager.js";
9-
import { AnonymousRequestPipelinePolicy } from "./cdn/cdnRequestPipelinePolicy.js";
9+
import { AnonymousRequestPipelinePolicy, RemoveSyncTokenPipelinePolicy } from "./cdn/cdnRequestPipelinePolicy.js";
1010
import { instanceOfTokenCredential } from "./common/utils.js";
1111
import { ArgumentError } from "./common/errors.js";
1212
import { ErrorMessages } from "./common/errorMessages.js";
@@ -87,10 +87,10 @@ export async function loadFromAzureFrontDoor(
8787

8888
appConfigOptions.clientOptions = {
8989
...appConfigOptions.clientOptions,
90-
// Add etag url policy to append etag to the request url for breaking CDN cache
9190
additionalPolicies: [
9291
...(appConfigOptions.clientOptions?.additionalPolicies || []),
93-
{ policy: new AnonymousRequestPipelinePolicy(), position: "perRetry" }
92+
{ policy: new AnonymousRequestPipelinePolicy(), position: "perRetry" },
93+
{ policy: new RemoveSyncTokenPipelinePolicy(), position: "perRetry" }
9494
]
9595
};
9696

test/cdn.test.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ chai.use(chaiAsPromised);
88
const expect = chai.expect;
99

1010
import { AppConfigurationClient } from "@azure/app-configuration";
11-
import { loadFromAzureFrontDoor } from "../src/index.js";
12-
import { createMockedKeyValue, createMockedFeatureFlag, HttpRequestHeadersPolicy, getCachedIterator, sinon, restoreMocks, createMockedAzureFrontDoorEndpoint, sleepInMs } from "./utils/testHelper.js";
11+
import { load, loadFromAzureFrontDoor } from "../src/index.js";
12+
import { createMockedKeyValue, createMockedFeatureFlag, HttpRequestHeadersPolicy, getCachedIterator, sinon, restoreMocks, createMockedConnectionString, createMockedAzureFrontDoorEndpoint, sleepInMs } from "./utils/testHelper.js";
1313
import { TIMESTAMP_HEADER } from "../src/cdn/constants.js";
1414
import { isBrowser } from "../src/requestTracing/utils.js";
1515

@@ -26,22 +26,39 @@ describe("loadFromAzureFrontDoor", function() {
2626
restoreMocks();
2727
});
2828

29-
it("should not include authorization headers", async () => {
29+
it("should not include authorization and sync-token header when loading from Azure Front Door", async () => {
3030
const headerPolicy = new HttpRequestHeadersPolicy();
3131
const position: "perCall" | "perRetry" = "perCall";
3232
const clientOptions = {
3333
retryOptions: {
34-
maxRetries: 0 // save time
34+
maxRetries: 0
3535
},
3636
additionalPolicies: [{
3737
policy: headerPolicy,
3838
position
39-
}]
39+
}],
40+
syncTokens: {
41+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
42+
addSyncTokenFromHeaderValue: (syncTokenHeaderValue) => {},
43+
getSyncTokenHeaderValue: () => { return "mockedSyncToken"; }
44+
}
4045
};
4146

42-
const endpoint = createMockedAzureFrontDoorEndpoint();
4347
try {
44-
await loadFromAzureFrontDoor(endpoint, {
48+
await load(createMockedConnectionString(), {
49+
clientOptions,
50+
startupOptions: {
51+
timeoutInMs: 1
52+
}
53+
});
54+
} catch { /* empty */ }
55+
56+
expect(headerPolicy.headers).not.undefined;
57+
expect(headerPolicy.headers.get("Authorization")).not.undefined;
58+
expect(headerPolicy.headers.get("Sync-Token")).to.equal("mockedSyncToken");
59+
60+
try {
61+
await loadFromAzureFrontDoor(createMockedAzureFrontDoorEndpoint(), {
4562
clientOptions,
4663
startupOptions: {
4764
timeoutInMs: 1
@@ -59,8 +76,8 @@ describe("loadFromAzureFrontDoor", function() {
5976
}
6077

6178
expect(userAgent).satisfy((ua: string) => ua.startsWith("javascript-appconfiguration-provider"));
62-
expect(headerPolicy.headers.get("authorization")).to.be.undefined;
6379
expect(headerPolicy.headers.get("Authorization")).to.be.undefined;
80+
expect(headerPolicy.headers.get("Sync-Token")).to.be.undefined;
6481
});
6582

6683
it("should load key-values and feature flags", async () => {
@@ -77,8 +94,7 @@ describe("loadFromAzureFrontDoor", function() {
7794
{ items: [ff], response: { status: 200, headers: createTimestampHeaders("2025-09-07T00:00:00Z") } }
7895
]));
7996

80-
const endpoint = createMockedAzureFrontDoorEndpoint();
81-
const appConfig = await loadFromAzureFrontDoor(endpoint, {
97+
const appConfig = await loadFromAzureFrontDoor(createMockedAzureFrontDoorEndpoint(), {
8298
selectors: [{ keyFilter: "app.*" }],
8399
featureFlagOptions: {
84100
enabled: true
@@ -123,8 +139,7 @@ describe("loadFromAzureFrontDoor", function() {
123139
{ items: [kv1, kv3], response: { status: 200, headers: createTimestampHeaders("2025-09-07T00:00:05Z") } }
124140
]));
125141

126-
const endpoint = createMockedAzureFrontDoorEndpoint();
127-
const appConfig = await loadFromAzureFrontDoor(endpoint, {
142+
const appConfig = await loadFromAzureFrontDoor(createMockedAzureFrontDoorEndpoint(), {
128143
selectors: [{ keyFilter: "app.*" }],
129144
refreshOptions: {
130145
enabled: true,
@@ -171,8 +186,7 @@ describe("loadFromAzureFrontDoor", function() {
171186
{ items: [ff_updated], response: { status: 200, headers: createTimestampHeaders("2025-09-07T00:00:00Z") } }
172187
]));
173188

174-
const endpoint = createMockedAzureFrontDoorEndpoint();
175-
const appConfig = await loadFromAzureFrontDoor(endpoint, {
189+
const appConfig = await loadFromAzureFrontDoor(createMockedAzureFrontDoorEndpoint(), {
176190
featureFlagOptions: {
177191
enabled: true,
178192
refresh: {
@@ -221,8 +235,7 @@ describe("loadFromAzureFrontDoor", function() {
221235
{ items: [kv1, kv2_updated], response: { status: 200, headers: createTimestampHeaders("2025-09-07T00:00:02Z") } } // cache has expired
222236
]));
223237

224-
const endpoint = createMockedAzureFrontDoorEndpoint();
225-
const appConfig = await loadFromAzureFrontDoor(endpoint, {
238+
const appConfig = await loadFromAzureFrontDoor(createMockedAzureFrontDoorEndpoint(), {
226239
selectors: [{ keyFilter: "app.*" }],
227240
refreshOptions: {
228241
enabled: true,

0 commit comments

Comments
 (0)