Hyperlinkv0.8.0-beta.28

NodeHttpClient

Effect.Effect<Client.HttpClient, never, Dispatcher>

Creates an HttpClient that sends requests through the current Undici Dispatcher, converts Effect HTTP bodies to Undici bodies, and maps transport and decode failures to HttpClientError.

Undici
export const makeUndici = Effect.gen(function*() {
  const dispatcher = yield* Dispatcher
  return Client.make((request, url, signal, fiber) =>
    convertBody(request.body).pipe(
      Effect.flatMap((body) =>
        Effect.tryPromise({
          try: () =>
            dispatcher.request({
              ...fiber.getRef(UndiciOptions),
              signal,
              method: request.method,
              headers: request.headers,
              origin: url.origin,
              path: url.pathname + url.search + url.hash,
              body,
              // leave timeouts to Effect.timeout etc
              headersTimeout: 60 * 60 * 1000,
              bodyTimeout: 0
            }),
          catch: (cause) =>
            new Error.HttpClientError({
              reason: new Error.TransportError({
                request,
                cause
              })
            })
        })
      ),
      Effect.map((response) => new UndiciResponse(request, response))
    )
  )
})
Referenced by 1 symbols