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