Skip to content

Commit

Permalink
Update local AI fetcher to forward method and pathname to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Nov 21, 2024
1 parent 09e6e90 commit 3729382
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-moons-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Update local AI fetcher to forward method and pathname to upstream
12 changes: 8 additions & 4 deletions packages/wrangler/src/ai/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ export default function (env) {
export async function AIFetcher(request: Request): Promise<Response> {
const accountId = await getAccountId();

request.headers.delete("Host");
request.headers.delete("Content-Length");
const url = new URL(request.url)

const reqHeaders = new Headers(request.headers);
reqHeaders.delete("Host");
reqHeaders.delete("Content-Length");
reqHeaders.set("x-pathname", url.pathname);

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

0 comments on commit 3729382

Please sign in to comment.