Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/content-type-repair.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/content-type-repair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading