-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathEtagUrlPipelinePolicy.ts
More file actions
29 lines (23 loc) · 1.13 KB
/
EtagUrlPipelinePolicy.ts
File metadata and controls
29 lines (23 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { PipelinePolicy } from "@azure/core-rest-pipeline";
export const ETAG_LOOKUP_HEADER = "Etag-Lookup";
/**
* The pipeline policy that retrieves the etag from the request header and appends it to the request URL. After that the etag header is removed from the request.
* @remarks
* The policy position should be perCall.
* The App Configuration service will not recognize the etag query parameter in the url, but this can help to break the CDN cache as the cache entry is based on the URL.
*/
export class EtagUrlPipelinePolicy implements PipelinePolicy {
name: string = "AppConfigurationEtagUrlPolicy";
async sendRequest(request, next) {
if (request.headers.has(ETAG_LOOKUP_HEADER)) {
const etag = request.headers.get(ETAG_LOOKUP_HEADER);
request.headers.delete(ETAG_LOOKUP_HEADER);
const url = new URL(request.url);
url.searchParams.append("_", etag); // _ is a dummy query parameter to break the CDN cache
request.url = url.toString();
}
return next(request);
}
}