* Transform the free-form body into a serialized format suitable for * transmission to the server.
()
| 440 | * transmission to the server. |
| 441 | */ |
| 442 | serializeBody(): ArrayBuffer | Blob | FormData | URLSearchParams | string | null { |
| 443 | // If no body is present, no need to serialize it. |
| 444 | if (this.body === null) { |
| 445 | return null; |
| 446 | } |
| 447 | // Check whether the body is already in a serialized form. If so, |
| 448 | // it can just be returned directly. |
| 449 | if ( |
| 450 | typeof this.body === 'string' || |
| 451 | isArrayBuffer(this.body) || |
| 452 | isBlob(this.body) || |
| 453 | isFormData(this.body) || |
| 454 | isUrlSearchParams(this.body) |
| 455 | ) { |
| 456 | return this.body; |
| 457 | } |
| 458 | // Check whether the body is an instance of HttpUrlEncodedParams. |
| 459 | if (this.body instanceof HttpParams) { |
| 460 | return this.body.toString(); |
| 461 | } |
| 462 | // Check whether the body is an object or array, and serialize with JSON if so. |
| 463 | if ( |
| 464 | typeof this.body === 'object' || |
| 465 | typeof this.body === 'boolean' || |
| 466 | Array.isArray(this.body) |
| 467 | ) { |
| 468 | return JSON.stringify(this.body); |
| 469 | } |
| 470 | // Fall back on toString() for everything else. |
| 471 | return (this.body as any).toString(); |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * Examine the body and attempt to infer an appropriate MIME type |
no test coverage detected