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

Function convertBody

packages/platform/node/src/NodeHttpClient.ts:341–364  ·  view source on GitHub ↗
(request: HttpClientRequest)

Source from the content-addressed store, hash-verified

339}
340
341function convertBody(request: HttpClientRequest): Effect.Effect<{
342 readonly body: Exclude<Undici.Dispatcher.DispatchOptions["body"], undefined>
343 readonly headers: Headers.Headers
344}> {
345 const { body, headers } = request
346 switch (body._tag) {
347 case "Empty": {
348 return Effect.succeed({ body: null, headers })
349 }
350 case "Uint8Array":
351 case "Raw": {
352 return Effect.succeed({ body: body.body as Uint8Array, headers })
353 }
354 case "FormData": {
355 return Effect.map(loadUndici, (undici) => ({
356 body: convertFormData(body.formData, undici),
357 headers: Headers.remove(headers, "content-type")
358 }))
359 }
360 case "Stream": {
361 return Effect.map(NodeStream.toReadable(body.stream), (body) => ({ body, headers }))
362 }
363 }
364}
365
366const convertFormData = (formData: FormData, undici: typeof Undici): Undici.FormData => {
367 const converted = new undici.FormData()

Callers 1

NodeHttpClient.tsFile · 0.85

Calls 4

convertFormDataFunction · 0.85
removeMethod · 0.65
succeedMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected