| 179 | reason: new HttpClientError.EncodeError({ request, ...options }) |
| 180 | }) |
| 181 | const send = (data: any) => |
| 182 | Effect.callback< |
| 183 | HttpClientResponse.HttpClientResponse, |
| 184 | HttpClientError.HttpClientError |
| 185 | >((resume) => { |
| 186 | const fail = (cause: unknown) => resume(Effect.fail(transportError(cause))) |
| 187 | if (signal.aborted) return fail(signal.reason) |
| 188 | const device = fiber.getRef(Native.Device) |
| 189 | const networking = device.module("Networking") |
| 190 | if (networking === undefined) { |
| 191 | return fail("React Native's Networking module isn't available") |
| 192 | } |
| 193 | const binary = fiber.getRef(ResponseType) === "binary" |
| 194 | const exchange = new Exchange(networking, exchangesOf(device)) |
| 195 | const ready = () => { |
| 196 | const head = exchange.head |
| 197 | if (head === undefined) { |
| 198 | if (exchange.error !== undefined) fail(exchange.error) |
| 199 | return |
| 200 | } |
| 201 | exchange.listeners.delete(ready) |
| 202 | resume(Effect.succeed( |
| 203 | new Response( |
| 204 | request, |
| 205 | head[1], |
| 206 | Headers.fromInput(head[2] ?? {}), |
| 207 | head[3] || url.href.split("#")[0], |
| 208 | exchange, |
| 209 | binary |
| 210 | ) |
| 211 | )) |
| 212 | } |
| 213 | exchange.listeners.add(ready) |
| 214 | const started = (id: number) => { |
| 215 | exchange.start(id) |
| 216 | // iOS assigns the ID asynchronously; cancellation may arrive first. |
| 217 | if (signal.aborted) exchange.abort() |
| 218 | } |
| 219 | signal.addEventListener("abort", exchange.abort, { once: true }) |
| 220 | const devToolsRequestId = (globalThis as any).__NETWORK_REPORTER__ |
| 221 | ?.createDevToolsRequestId() |
| 222 | const responseType = binary ? "base64" : "text" |
| 223 | if (device.os === "android") { |
| 224 | data.formData?.forEach((part: any) => { |
| 225 | part.headers = Object.entries(part.headers) |
| 226 | }) |
| 227 | started(nextId++) |
| 228 | networking.sendRequest( |
| 229 | request.method, |
| 230 | url.href, |
| 231 | exchange.id, |
| 232 | Object.entries(request.headers), |
| 233 | { ...data, devToolsRequestId }, |
| 234 | responseType, |
| 235 | !binary, |
| 236 | 0, |
| 237 | true |
| 238 | ) |