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", });