( request: HttpRequest<any>, mappedRequestUrl: string, )
| 408 | } |
| 409 | |
| 410 | function 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 | |
| 433 | function toBase64(buffer: unknown): string { |
| 434 | //TODO: replace with when is Baseline widely available |
no test coverage detected