diff --git a/src/content-type-repair.test.ts b/src/content-type-repair.test.ts index 98819f3..bf9bf89 100644 --- a/src/content-type-repair.test.ts +++ b/src/content-type-repair.test.ts @@ -79,6 +79,16 @@ describe("Codex content-type repair — missing content-type on 2xx SSE response expect(response.headers.get("content-type")).toBe("text/event-stream"); }); + test("repairs a relative URL instead of throwing", async () => { + const repaired = withCodexContentTypeRepair( + fetchReturning(new Response("data: {}\n\n", { status: 200 })), + ); + const response = await repaired(`/backend-api${CODEX_RESPONSES_PATH}`, { + headers: { accept: "text/event-stream" }, + }); + expect(response.headers.get("content-type")).toBe("text/event-stream"); + }); + test("treats an empty content-type as missing", async () => { const repaired = withCodexContentTypeRepair( fetchReturning( diff --git a/src/content-type-repair.ts b/src/content-type-repair.ts index 96d9247..46cb5b5 100644 --- a/src/content-type-repair.ts +++ b/src/content-type-repair.ts @@ -54,8 +54,8 @@ function acceptedContentType( export function withCodexContentTypeRepair(fetchImpl: FetchLike): FetchLike { return async (input, init) => { const response = await fetchImpl(input, init); - if (!new URL(requestURL(input)).pathname.endsWith(CODEX_RESPONSES_PATH)) - return response; + const { pathname } = new URL(requestURL(input), "http://localhost"); + if (!pathname.endsWith(CODEX_RESPONSES_PATH)) return response; if (!response.ok) return response; if (response.headers.get("content-type")) return response; const declared = acceptedContentType(input, init);