Skip to content

Commit

Permalink
Fix Workers AI local mode fetcher not returning headers to client wor…
Browse files Browse the repository at this point in the history
…ker (#5138)

* Fix Workers AI local mode fetcher not returning headers to client worker

* Trigger Build

* Update .changeset/yellow-phones-buy.md

Co-authored-by: MrBBot <me@mrbbot.dev>

* Update packages/wrangler/src/ai/fetcher.ts

Co-authored-by: MrBBot <me@mrbbot.dev>

* Add missing Headers import

* Lint changes

---------

Co-authored-by: MrBBot <me@mrbbot.dev>
  • Loading branch information
G4brym and mrbbot authored Mar 4, 2024
1 parent b745f7b commit 3dd9089
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-phones-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: ensure Workers-AI local mode fetcher returns headers to client worker
8 changes: 6 additions & 2 deletions packages/wrangler/src/ai/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Response } from "miniflare";
import { Headers, Response } from "miniflare";
import { performApiFetch } from "../cfetch/internal";
import { getAccountId } from "../user";
import type { Request } from "miniflare";
Expand All @@ -16,5 +16,9 @@ export async function AIFetcher(request: Request) {
duplex: "half",
});

return new Response(res.body, { status: res.status });
const respHeaders = new Headers(res.headers);
respHeaders.delete("Host");
respHeaders.delete("Content-Length");

return new Response(res.body, { status: res.status, headers: respHeaders });
}

0 comments on commit 3dd9089

Please sign in to comment.