( xhr: XMLHttpRequest, request: ClientRequest.HttpClientRequest )
| 81 | ) |
| 82 | |
| 83 | const sendBody = ( |
| 84 | xhr: XMLHttpRequest, |
| 85 | request: ClientRequest.HttpClientRequest |
| 86 | ): Effect.Effect<void, Error.RequestError> => { |
| 87 | const body = request.body |
| 88 | switch (body._tag) { |
| 89 | case "Empty": |
| 90 | return Effect.sync(() => xhr.send()) |
| 91 | case "Raw": |
| 92 | return Effect.sync(() => xhr.send(body.body as any)) |
| 93 | case "Uint8Array": |
| 94 | return Effect.sync(() => xhr.send(body.body)) |
| 95 | case "FormData": |
| 96 | return Effect.sync(() => xhr.send(body.formData)) |
| 97 | case "Stream": |
| 98 | return Effect.matchEffect( |
| 99 | Stream.runFold(body.stream, new Uint8Array(0), (acc, chunk) => { |
| 100 | const next = new Uint8Array(acc.length + chunk.length) |
| 101 | next.set(acc, 0) |
| 102 | next.set(chunk, acc.length) |
| 103 | return next |
| 104 | }), |
| 105 | { |
| 106 | onFailure: (cause) => |
| 107 | Effect.fail( |
| 108 | new Error.RequestError({ |
| 109 | request, |
| 110 | reason: "Encode", |
| 111 | cause |
| 112 | }) |
| 113 | ), |
| 114 | onSuccess: (body) => Effect.sync(() => xhr.send(body)) |
| 115 | } |
| 116 | ) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | const encoder = new TextEncoder() |
| 121 |
no test coverage detected