MCPcopy
hub / github.com/Effect-TS/effect / sendBody

Function sendBody

packages/platform-browser/src/internal/httpClient.ts:83–118  ·  view source on GitHub ↗
(
  xhr: XMLHttpRequest,
  request: ClientRequest.HttpClientRequest
)

Source from the content-addressed store, hash-verified

81)
82
83const 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
120const encoder = new TextEncoder()
121

Callers 1

httpClient.tsFile · 0.70

Calls 3

syncMethod · 0.80
setMethod · 0.65
failMethod · 0.65

Tested by

no test coverage detected