(req: HttpRequest<any>)
| 368 | } |
| 369 | |
| 370 | private createRequestInit(req: HttpRequest<any>): RequestInit { |
| 371 | if (req.reportUploadProgress) { |
| 372 | throw new RuntimeError( |
| 373 | RuntimeErrorCode.FETCH_UPLOAD_PROGRESS_NOT_SUPPORTED, |
| 374 | ngDevMode && |
| 375 | 'The FetchBackend does not support upload progress reporting. Please use `withXhr()` on your `provideHttpClient()` configuration if you want to report upload progress.', |
| 376 | ); |
| 377 | } |
| 378 | |
| 379 | // We could share some of this logic with the XhrBackend |
| 380 | const headers: Record<string, string> = {}; |
| 381 | let credentials: RequestCredentials | undefined; |
| 382 | |
| 383 | // If the request has a credentials property, use it. |
| 384 | // Otherwise, if the request has withCredentials set to true, use 'include'. |
| 385 | credentials = req.credentials; |
| 386 | |
| 387 | // If withCredentials is true should be set to 'include', for compatibility |
| 388 | if (req.withCredentials) { |
| 389 | // A warning is logged in development mode if the request has both |
| 390 | (typeof ngDevMode === 'undefined' || ngDevMode) && warningOptionsMessage(req); |
| 391 | credentials = 'include'; |
| 392 | } |
| 393 | |
| 394 | // Setting all the requested headers. |
| 395 | req.headers.forEach((name, values) => (headers[name] = values.join(','))); |
| 396 | |
| 397 | // Add an Accept header if one isn't present already. |
| 398 | if (!req.headers.has(ACCEPT_HEADER)) { |
| 399 | headers[ACCEPT_HEADER] = ACCEPT_HEADER_VALUE; |
| 400 | } |
| 401 | |
| 402 | // Auto-detect the Content-Type header if one isn't present already. |
| 403 | if (!req.headers.has(CONTENT_TYPE_HEADER)) { |
| 404 | const detectedType = req.detectContentTypeHeader(); |
| 405 | // Sometimes Content-Type detection fails. |
| 406 | if (detectedType !== null) { |
| 407 | headers[CONTENT_TYPE_HEADER] = detectedType; |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | return { |
| 412 | body: req.serializeBody(), |
| 413 | method: req.method, |
| 414 | headers, |
| 415 | credentials, |
| 416 | keepalive: req.keepalive, |
| 417 | cache: req.cache, |
| 418 | priority: req.priority, |
| 419 | mode: req.mode, |
| 420 | redirect: req.redirect, |
| 421 | referrer: req.referrer, |
| 422 | integrity: req.integrity, |
| 423 | referrerPolicy: req.referrerPolicy, |
| 424 | }; |
| 425 | } |
| 426 | |
| 427 | private concatChunks(chunks: Uint8Array[], totalLength: number): Uint8Array<ArrayBuffer> { |
no test coverage detected