( request: HttpClientRequest.HttpClientRequest, headers: Headers, body: BodyInit | null | undefined, )
| 187 | }); |
| 188 | |
| 189 | const applyBody = async ( |
| 190 | request: HttpClientRequest.HttpClientRequest, |
| 191 | headers: Headers, |
| 192 | body: BodyInit | null | undefined, |
| 193 | ): Promise<HttpClientRequest.HttpClientRequest> => { |
| 194 | if (body == null) return request; |
| 195 | const contentType = headers.get("content-type") ?? undefined; |
| 196 | if (typeof body === "string") return HttpClientRequest.bodyText(request, body, contentType); |
| 197 | if (body instanceof URLSearchParams) { |
| 198 | return HttpClientRequest.bodyText( |
| 199 | request, |
| 200 | body.toString(), |
| 201 | contentType ?? "application/x-www-form-urlencoded;charset=UTF-8", |
| 202 | ); |
| 203 | } |
| 204 | if (body instanceof Uint8Array) |
| 205 | return HttpClientRequest.bodyUint8Array(request, body, contentType); |
| 206 | if (body instanceof ArrayBuffer) { |
| 207 | return HttpClientRequest.bodyUint8Array(request, new Uint8Array(body), contentType); |
| 208 | } |
| 209 | const bytes = new Uint8Array(await new Response(body).arrayBuffer()); |
| 210 | return HttpClientRequest.bodyUint8Array(request, bytes, contentType); |
| 211 | }; |
| 212 | |
| 213 | const abortError = (signal: AbortSignal): unknown => { |
| 214 | if (signal.reason !== undefined) return signal.reason; |
no test coverage detected