From e80448fe905b42618862d2286c9dcd47c7ff6eb3 Mon Sep 17 00:00:00 2001 From: Gabriel Massadas Date: Thu, 21 Nov 2024 15:01:52 +0000 Subject: [PATCH] Update local AI fetcher to forward method and pathname to upstream --- .changeset/stupid-moons-juggle.md | 5 +++++ packages/wrangler/src/ai/fetcher.ts | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 .changeset/stupid-moons-juggle.md diff --git a/.changeset/stupid-moons-juggle.md b/.changeset/stupid-moons-juggle.md new file mode 100644 index 000000000000..6049cdc69c54 --- /dev/null +++ b/.changeset/stupid-moons-juggle.md @@ -0,0 +1,5 @@ +--- +"wrangler": minor +--- + +Update local AI fetcher to forward method and pathname to upstream diff --git a/packages/wrangler/src/ai/fetcher.ts b/packages/wrangler/src/ai/fetcher.ts index 6660bb048ade..2fe8685c5636 100644 --- a/packages/wrangler/src/ai/fetcher.ts +++ b/packages/wrangler/src/ai/fetcher.ts @@ -16,12 +16,14 @@ export default function (env) { export async function AIFetcher(request: Request): Promise { const accountId = await getAccountId(); - request.headers.delete("Host"); - request.headers.delete("Content-Length"); + const reqHeaders = new Headers(request.headers); + reqHeaders.delete("Host"); + reqHeaders.delete("Content-Length"); + reqHeaders.set("x-url", request.url); const res = await performApiFetch(`/accounts/${accountId}/ai/run/proxy`, { - method: "POST", - headers: Object.fromEntries(request.headers.entries()), + method: request.method, + headers: Object.fromEntries(reqHeaders.entries()), body: request.body, duplex: "half", });