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

Method detectContentTypeHeader

packages/common/http/src/request.ts:480–517  ·  view source on GitHub ↗

* Examine the body and attempt to infer an appropriate MIME type * for it. * * If no such type can be inferred, this method will return `null`.

()

Source from the content-addressed store, hash-verified

478 * If no such type can be inferred, this method will return `null`.
479 */
480 detectContentTypeHeader(): string | null {
481 // An empty body has no content type.
482 if (this.body === null) {
483 return null;
484 }
485 // FormData bodies rely on the browser's content type assignment.
486 if (isFormData(this.body)) {
487 return null;
488 }
489 // Blobs usually have their own content type. If it doesn't, then
490 // no type can be inferred.
491 if (isBlob(this.body)) {
492 return this.body.type || null;
493 }
494 // Array buffers have unknown contents and thus no type can be inferred.
495 if (isArrayBuffer(this.body)) {
496 return null;
497 }
498 // Technically, strings could be a form of JSON data, but it's safe enough
499 // to assume they're plain strings.
500 if (typeof this.body === 'string') {
501 return TEXT_CONTENT_TYPE;
502 }
503 // `HttpUrlEncodedParams` has its own content-type.
504 if (this.body instanceof HttpParams) {
505 return 'application/x-www-form-urlencoded;charset=UTF-8';
506 }
507 // Arrays, objects, boolean and numbers will be encoded as JSON.
508 if (
509 typeof this.body === 'object' ||
510 typeof this.body === 'number' ||
511 typeof this.body === 'boolean'
512 ) {
513 return JSON_CONTENT_TYPE;
514 }
515 // No type could be inferred.
516 return null;
517 }
518
519 clone(): HttpRequest<T>;
520 clone(

Callers 3

request_spec.tsFile · 0.80
handleMethod · 0.80
createRequestInitMethod · 0.80

Calls 3

isFormDataFunction · 0.85
isBlobFunction · 0.85
isArrayBufferFunction · 0.85

Tested by

no test coverage detected