From d5c2e39c9868c4a6a038edf08e4a1d90a79107a7 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Fri, 1 Mar 2024 18:22:24 +0000 Subject: [PATCH 1/6] Fix Workers AI local mode fetcher not returning headers to client worker --- .changeset/yellow-phones-buy.md | 5 +++++ packages/wrangler/src/ai/fetcher.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/yellow-phones-buy.md diff --git a/.changeset/yellow-phones-buy.md b/.changeset/yellow-phones-buy.md new file mode 100644 index 000000000000..5f6ba4a8e27d --- /dev/null +++ b/.changeset/yellow-phones-buy.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Fix Workers-AI local mode fetcher not returning headers to client worker diff --git a/packages/wrangler/src/ai/fetcher.ts b/packages/wrangler/src/ai/fetcher.ts index 85c2ce25ebf2..c25738e91b93 100644 --- a/packages/wrangler/src/ai/fetcher.ts +++ b/packages/wrangler/src/ai/fetcher.ts @@ -16,5 +16,12 @@ export async function AIFetcher(request: Request) { duplex: "half", }); - return new Response(res.body, { status: res.status }); + const respHeaders: Record = {}; + for (const [name, value] of res.headers) { + respHeaders[name] = value; + } + respHeaders.headers.delete("Host"); + respHeaders.headers.delete("Content-Length"); + + return new Response(res.body, { status: res.status, headers: respHeaders }); } From 14896507f7fda626e0a02e232d496ed43f1cc125 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Fri, 1 Mar 2024 18:38:51 +0000 Subject: [PATCH 2/6] Trigger Build From 5d17e86878b78388e05a927d4eed51e7328f4997 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas <5445926+G4brym@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:29:39 +0000 Subject: [PATCH 3/6] Update .changeset/yellow-phones-buy.md Co-authored-by: MrBBot --- .changeset/yellow-phones-buy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/yellow-phones-buy.md b/.changeset/yellow-phones-buy.md index 5f6ba4a8e27d..9f0dc009434d 100644 --- a/.changeset/yellow-phones-buy.md +++ b/.changeset/yellow-phones-buy.md @@ -2,4 +2,4 @@ "wrangler": patch --- -Fix Workers-AI local mode fetcher not returning headers to client worker +fix: ensure Workers-AI local mode fetcher returns headers to client worker From 28604593e660d38dffa51503c70f22af92f4084f Mon Sep 17 00:00:00 2001 From: Gabriel Massadas <5445926+G4brym@users.noreply.github.com> Date: Mon, 4 Mar 2024 10:30:20 +0000 Subject: [PATCH 4/6] Update packages/wrangler/src/ai/fetcher.ts Co-authored-by: MrBBot --- packages/wrangler/src/ai/fetcher.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/wrangler/src/ai/fetcher.ts b/packages/wrangler/src/ai/fetcher.ts index c25738e91b93..7b3b04ca7209 100644 --- a/packages/wrangler/src/ai/fetcher.ts +++ b/packages/wrangler/src/ai/fetcher.ts @@ -16,12 +16,9 @@ export async function AIFetcher(request: Request) { duplex: "half", }); - const respHeaders: Record = {}; - for (const [name, value] of res.headers) { - respHeaders[name] = value; - } - respHeaders.headers.delete("Host"); - respHeaders.headers.delete("Content-Length"); + const respHeaders = new Headers(res.headers); + respHeaders.delete("Host"); + respHeaders.delete("Content-Length"); return new Response(res.body, { status: res.status, headers: respHeaders }); } From e23ff72541f2a23b5935be9e24a43c1cd84fe907 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Mon, 4 Mar 2024 10:31:23 +0000 Subject: [PATCH 5/6] Add missing Headers import --- packages/wrangler/src/ai/fetcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wrangler/src/ai/fetcher.ts b/packages/wrangler/src/ai/fetcher.ts index 7b3b04ca7209..8759b136df01 100644 --- a/packages/wrangler/src/ai/fetcher.ts +++ b/packages/wrangler/src/ai/fetcher.ts @@ -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"; From ee2da8cf1f60232bd57378839e3bf3a3543c20db Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Mon, 4 Mar 2024 10:32:34 +0000 Subject: [PATCH 6/6] Lint changes --- packages/wrangler/src/ai/fetcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wrangler/src/ai/fetcher.ts b/packages/wrangler/src/ai/fetcher.ts index 8759b136df01..7fa8472afb49 100644 --- a/packages/wrangler/src/ai/fetcher.ts +++ b/packages/wrangler/src/ai/fetcher.ts @@ -1,4 +1,4 @@ -import {Headers, Response } from "miniflare"; +import { Headers, Response } from "miniflare"; import { performApiFetch } from "../cfetch/internal"; import { getAccountId } from "../user"; import type { Request } from "miniflare";