MCPcopy Create free account
hub / github.com/angular/angular / makeCacheKey

Function makeCacheKey

packages/common/http/src/transfer_cache.ts:413–434  ·  view source on GitHub ↗
(
  request: HttpRequest<any>,
  mappedRequestUrl: string,
)

Source from the content-addressed store, hash-verified

411}
412
413function makeCacheKey(
414 request: HttpRequest<any>,
415 mappedRequestUrl: string,
416): StateKey<TransferHttpResponse> {
417 const {params, method, responseType} = request;
418 const encodedParams = sortAndConcatParams(params);
419
420 let serializedBody = request.serializeBody();
421 if (serializedBody instanceof URLSearchParams) {
422 serializedBody = sortAndConcatParams(serializedBody);
423 } else if (typeof serializedBody !== 'string') {
424 serializedBody = '';
425 }
426
427 // Joining with `|` lets a shifted field boundary (url `/a` + body `b|c` vs url `/a|b` + body `c`)
428 // collapse to the same string and thus the same hash. `\0` cannot occur in a valid url or in
429 // encoded params, so the field boundaries can't be forged by field content.
430 const key = [method, responseType, mappedRequestUrl, serializedBody, encodedParams].join('\0');
431 const hash = generateHash(key);
432
433 return makeStateKey(hash);
434}
435
436function toBase64(buffer: unknown): string {
437 //TODO: replace with when is Baseline widely available

Callers 2

retrieveStateFromCacheFunction · 0.85

Calls 5

makeStateKeyFunction · 0.90
sortAndConcatParamsFunction · 0.85
generateHashFunction · 0.85
serializeBodyMethod · 0.80
joinMethod · 0.65

Tested by

no test coverage detected