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 6346622
Show file tree
Hide file tree
Showing 2 changed files with 11 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 url to upstream
10 changes: 6 additions & 4 deletions packages/wrangler/src/ai/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ 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 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",
});
Expand Down

0 comments on commit 6346622

Please sign in to comment.