(
f: (
request: HttpClientRequest.HttpClientRequest,
url: URL,
signal: AbortSignal,
fiber: Fiber.Fiber<HttpClientResponse.HttpClientResponse, Error.HttpClientError>
) => Effect.Effect<HttpClientResponse.HttpClientResponse, Error.HttpClientError>
)
| 690 | * @since 4.0.0 |
| 691 | */ |
| 692 | export const make = ( |
| 693 | f: ( |
| 694 | request: HttpClientRequest.HttpClientRequest, |
| 695 | url: URL, |
| 696 | signal: AbortSignal, |
| 697 | fiber: Fiber.Fiber<HttpClientResponse.HttpClientResponse, Error.HttpClientError> |
| 698 | ) => Effect.Effect<HttpClientResponse.HttpClientResponse, Error.HttpClientError> |
| 699 | ): HttpClient => |
| 700 | makeWith((effect) => |
| 701 | Effect.flatMap(effect, (request) => |
| 702 | Effect.withFiber((fiber) => { |
| 703 | const scope = fiber.getRef(RequestScope) |
| 704 | const controller = new AbortController() |
| 705 | const urlParamsRedactedNames = fiber.getRef(UrlParams.CurrentRedactedNames) |
| 706 | const redactedPath = fiber.getRef(CurrentClientPath) |
| 707 | const urlResult = Url.make(request.url, request.urlParams, Option.getOrUndefined(request.hash)) |
| 708 | if (Result.isFailure(urlResult)) { |
| 709 | const cause = Cause.fail( |
| 710 | new Error.HttpClientError({ |
| 711 | reason: new Error.InvalidUrlError({ |
| 712 | request, |
| 713 | cause: urlResult.failure |
| 714 | }) |
| 715 | }) |
| 716 | ) |
| 717 | Error.addFailureRedactedNames(cause, urlParamsRedactedNames, redactedPath) |
| 718 | return Effect.failCause(cause) |
| 719 | } |
| 720 | const url = urlResult.success |
| 721 | const send = (request: HttpClientRequest.HttpClientRequest) => |
| 722 | scope === undefined |
| 723 | ? f(request, url, controller.signal, fiber as any) |
| 724 | // Register the abort before dispatch, so a scope that is already |
| 725 | // closed aborts the signal before the transport sees it |
| 726 | : Effect.flatMap( |
| 727 | Scope.addFinalizer(scope, Effect.sync(() => controller.abort())), |
| 728 | () => f(request, url, controller.signal, fiber as any) |
| 729 | ) |
| 730 | const exchange = ( |
| 731 | request: HttpClientRequest.HttpClientRequest, |
| 732 | onResponse?: (response: HttpClientResponse.HttpClientResponse) => void |
| 733 | ) => |
| 734 | Effect.uninterruptibleMask((restore) => |
| 735 | Effect.matchCauseEffect(restore(send(request)), { |
| 736 | onSuccess: (response) => { |
| 737 | response = trackResponse( |
| 738 | response, |
| 739 | controller, |
| 740 | scope !== undefined, |
| 741 | urlParamsRedactedNames, |
| 742 | redactedPath |
| 743 | ) |
| 744 | onResponse?.(response) |
| 745 | return Effect.succeed(response) |
| 746 | }, |
| 747 | onFailure: (cause) => { |
| 748 | if (Cause.hasInterrupts(cause)) { |
| 749 | controller.abort() |
nothing calls this directly
no test coverage detected