MCPcopy Create free account
hub / github.com/Effect-TS/effect / sendBody

Function sendBody

packages/platform/browser/src/BrowserHttpClient.ts:200–231  ·  view source on GitHub ↗
(
  xhr: globalThis.XMLHttpRequest,
  request: HttpClientRequest.HttpClientRequest
)

Source from the content-addressed store, hash-verified

198)
199
200const sendBody = (
201 xhr: globalThis.XMLHttpRequest,
202 request: HttpClientRequest.HttpClientRequest
203): Effect.Effect<void, HttpClientError.HttpClientError> => {
204 const body = request.body
205 switch (body._tag) {
206 case "Empty":
207 return Effect.sync(() => xhr.send())
208 case "Raw":
209 return Effect.sync(() => xhr.send(body.body as any))
210 case "Uint8Array":
211 return Effect.sync(() => xhr.send(body.body as any))
212 case "FormData":
213 return Effect.sync(() => xhr.send(body.formData))
214 case "Stream":
215 return Effect.matchEffect(
216 Stream.mkUint8Array(body.stream),
217 {
218 onFailure: (cause) =>
219 Effect.fail(
220 new HttpClientError.HttpClientError({
221 reason: new HttpClientError.EncodeError({
222 request,
223 cause
224 })
225 })
226 ),
227 onSuccess: (body) => Effect.sync(() => xhr.send(body))
228 }
229 )
230 }
231}
232
233const encoder = new TextEncoder()
234

Callers 1

Calls 3

sendMethod · 0.65
failMethod · 0.65
syncMethod · 0.45

Tested by

no test coverage detected