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

Function makeCacheKey

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

Source from the content-addressed store, hash-verified

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