MCPcopy Index your code
hub / github.com/angular/angular / createRequestInit

Method createRequestInit

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

Source from the content-addressed store, hash-verified

348 }
349
350 private createRequestInit(req: HttpRequest<any>): RequestInit {
351 if (req.reportUploadProgress) {
352 throw new RuntimeError(
353 RuntimeErrorCode.FETCH_UPLOAD_PROGRESS_NOT_SUPPORTED,
354 ngDevMode &&
355 'The FetchBackend does not support upload progress reporting. Please use `withXhr()` on your `provideHttpClient()` configuration if you want to report upload progress.',
356 );
357 }
358
359 // We could share some of this logic with the XhrBackend
360 const headers: Record<string, string> = {};
361 let credentials: RequestCredentials | undefined;
362
363 // If the request has a credentials property, use it.
364 // Otherwise, if the request has withCredentials set to true, use 'include'.
365 credentials = req.credentials;
366
367 // If withCredentials is true should be set to 'include', for compatibility
368 if (req.withCredentials) {
369 // A warning is logged in development mode if the request has both
370 (typeof ngDevMode === 'undefined' || ngDevMode) && warningOptionsMessage(req);
371 credentials = 'include';
372 }
373
374 // Setting all the requested headers.
375 req.headers.forEach((name, values) => (headers[name] = values.join(',')));
376
377 // Add an Accept header if one isn't present already.
378 if (!req.headers.has(ACCEPT_HEADER)) {
379 headers[ACCEPT_HEADER] = ACCEPT_HEADER_VALUE;
380 }
381
382 // Auto-detect the Content-Type header if one isn't present already.
383 if (!req.headers.has(CONTENT_TYPE_HEADER)) {
384 const detectedType = req.detectContentTypeHeader();
385 // Sometimes Content-Type detection fails.
386 if (detectedType !== null) {
387 headers[CONTENT_TYPE_HEADER] = detectedType;
388 }
389 }
390
391 return {
392 body: req.serializeBody(),
393 method: req.method,
394 headers,
395 credentials,
396 keepalive: req.keepalive,
397 cache: req.cache,
398 priority: req.priority,
399 mode: req.mode,
400 redirect: req.redirect,
401 referrer: req.referrer,
402 integrity: req.integrity,
403 referrerPolicy: req.referrerPolicy,
404 };
405 }
406
407 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