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

Method createRequestInit

packages/common/http/src/fetch.ts:371–426  ·  view source on GitHub ↗
(req: HttpRequest<any>)

Source from the content-addressed store, hash-verified

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

Callers 1

doRequestMethod · 0.95

Calls 6

warningOptionsMessageFunction · 0.85
serializeBodyMethod · 0.80
joinMethod · 0.65
hasMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected