( request: HttpClientRequest.HttpClientRequest, headers: Headers, body: BodyInit | null | undefined, )
| 207 | }); |
| 208 | |
| 209 | const applyBody = async ( |
| 210 | request: HttpClientRequest.HttpClientRequest, |
| 211 | headers: Headers, |
| 212 | body: BodyInit | null | undefined, |
| 213 | ): Promise<HttpClientRequest.HttpClientRequest> => { |
| 214 | if (body == null) return request; |
| 215 | const contentType = headers.get("content-type") ?? undefined; |
| 216 | if (typeof body === "string") return HttpClientRequest.bodyText(request, body, contentType); |
| 217 | if (body instanceof URLSearchParams) { |
| 218 | return HttpClientRequest.bodyText( |
| 219 | request, |
| 220 | body.toString(), |
| 221 | contentType ?? "application/x-www-form-urlencoded;charset=UTF-8", |
| 222 | ); |
| 223 | } |
| 224 | if (body instanceof Uint8Array) |
| 225 | return HttpClientRequest.bodyUint8Array(request, body, contentType); |
| 226 | if (body instanceof ArrayBuffer) { |
| 227 | return HttpClientRequest.bodyUint8Array(request, new Uint8Array(body), contentType); |
| 228 | } |
| 229 | const bytes = new Uint8Array(await new Response(body).arrayBuffer()); |
| 230 | return HttpClientRequest.bodyUint8Array(request, bytes, contentType); |
| 231 | }; |
| 232 | |
| 233 | const abortError = (signal: AbortSignal): unknown => { |
| 234 | if (signal.reason !== undefined) return signal.reason; |
no test coverage detected