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