| @@ -18,6 +18,7 @@ import { describe, expect, it } from "@effect/vitest"; · 17 unmodified lines |
| 18 | import { env } from "cloudflare:workers"; | 18 | import { env } from "cloudflare:workers"; |
| 19 | import * as Effect from "effect/Effect"; | 19 | import * as Effect from "effect/Effect"; |
| 20 | import * as Layer from "effect/Layer"; | 20 | import * as Layer from "effect/Layer"; |
| | 21 | import * as Predicate from "effect/Predicate"; |
| 21 | import { HttpClient, HttpClientResponse, type HttpClientRequest } from "effect/unstable/http"; | 22 | import { HttpClient, HttpClientResponse, type HttpClientRequest } from "effect/unstable/http"; |
| 22 | | 23 | |
| 23 | import { | 24 | import { |
| @@ -85,15 +86,17 @@ const makeRecordingHttpClient = () => { · 61 unmodified lines |
| 85 | const headers = { ...request.headers }; | 86 | const headers = { ...request.headers }; |
| 86 | let bytes = new Uint8Array(); | 87 | let bytes = new Uint8Array(); |
| 87 | let contentType = headers["content-type"] ?? ""; | 88 | let contentType = headers["content-type"] ?? ""; |
| 88 | const tag = request.body._tag; | 89 | const isRaw = Predicate.isTagged(request.body, "Raw"); |
| | 90 | const isUint8Array = Predicate.isTagged(request.body, "Uint8Array"); |
| | 91 | const isFormData = Predicate.isTagged(request.body, "FormData"); |
| 89 | | 92 | |
| 90 | if (tag === "Raw" || tag === "Uint8Array") { | 93 | if (isRaw || isUint8Array) { |
| 91 | const wire = new Request("http://capture/", { | 94 | const wire = new Request("http://capture/", { |
| 92 | method: "POST", | 95 | method: "POST", |
| 93 | body: request.body.body as BodyInit, | 96 | body: request.body.body as BodyInit, |
| 94 | }); | 97 | }); |
| 95 | bytes = new Uint8Array(yield* Effect.promise(() => wire.arrayBuffer())); | 98 | bytes = new Uint8Array(yield* Effect.promise(() => wire.arrayBuffer())); |
| 96 | } else if (tag === "FormData") { | 99 | } else if (isFormData) { |
| 97 | // Letting `Response` realize the FormData yields the actual | 100 | // Letting `Response` realize the FormData yields the actual |
| 98 | // multipart wire bytes plus a generated boundary in its | 101 | // multipart wire bytes plus a generated boundary in its |
| 99 | // content-type header — exactly what the upstream server sees. | 102 | // content-type header — exactly what the upstream server sees. |
| @@ -106,7 +109,7 @@ const makeRecordingHttpClient = () => { · 6 unmodified lines |
| 106 | url: request.url, | 109 | url: request.url, |
| 107 | method: request.method, | 110 | method: request.method, |
| 108 | contentType, | 111 | contentType, |
| 109 | bodyKind: tag, | 112 | bodyKind: isRaw ? "Raw" : isUint8Array ? "Uint8Array" : isFormData ? "FormData" : "", |
| 110 | body: bytes, | 113 | body: bytes, |
| 111 | }); | 114 | }); |
| 112 | | 115 | |