Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update local AI fetcher to forward method and pathname to upstream #7315

Conversation

G4brym
Copy link
Member

@G4brym G4brym commented Nov 21, 2024

This pr starts forwarding method and url to upstream.
This is not a breaking change, because the AI binding currently just does POST requests.

workerd here


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because: current tests already cover this change
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: current tests already cover this change
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: just a small improvement, it doesn't change anything from a user perspective

@G4brym G4brym requested a review from a team as a code owner November 21, 2024 15:05
Copy link

changeset-bot bot commented Nov 21, 2024

🦋 Changeset detected

Latest commit: 931acf7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 21, 2024

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-wrangler-7315

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7315/npm-package-wrangler-7315

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-wrangler-7315 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-create-cloudflare-7315 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-cloudflare-kv-asset-handler-7315
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-miniflare-7315
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-cloudflare-pages-shared-7315
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-cloudflare-vitest-pool-workers-7315
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-cloudflare-workers-editor-shared-7315
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-cloudflare-workers-shared-7315
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/11971817665/npm-package-cloudflare-workflows-shared-7315

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241106.1
workerd 1.20241106.1 1.20241106.1
workerd --version 1.20241106.1 2024-11-06

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

@G4brym G4brym force-pushed the update-local-ai-fetcher-to-forward-request-and-method branch from 33e5ba9 to e80448f Compare November 21, 2024 15:21
@G4brym G4brym force-pushed the update-local-ai-fetcher-to-forward-request-and-method branch from e80448f to 6346622 Compare November 21, 2024 15:22
@G4brym G4brym force-pushed the update-local-ai-fetcher-to-forward-request-and-method branch from a45b81d to 77d5dfe Compare November 21, 2024 16:16
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there no test you can update or create for this behaviour?

packages/wrangler/src/ai/fetcher.ts Outdated Show resolved Hide resolved
@G4brym
Copy link
Member Author

G4brym commented Nov 21, 2024

@petebacondarwin sure, let me add a test and get back to you
Regarding the header name, i don't think "X-Forwarded-Host" fits well, because we are forwarding the complete url, not just the hostname, i guess nothing stops us from doing it anyway, it might just be confusing for someone new
The part we are really interested is in the utl pathname + querystring, so i thought i might as well send the complete url

@G4brym G4brym force-pushed the update-local-ai-fetcher-to-forward-request-and-method branch from 4c82497 to 7e38dd1 Compare November 21, 2024 19:23
@G4brym G4brym force-pushed the update-local-ai-fetcher-to-forward-request-and-method branch from 6136571 to 8d93ebc Compare November 21, 2024 20:34
@G4brym
Copy link
Member Author

G4brym commented Nov 21, 2024

Hey @petebacondarwin I've just updated the pr with new tests and new header name
Please take a look when you have time, thanks

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the tests!
Sorry if I sent you off on a trip with that header name.

Please can you check it is valid and what you actually need on the server-side.

const reqHeaders = new Headers(request.headers);
reqHeaders.delete("Host");
reqHeaders.delete("Content-Length");
reqHeaders.set("X-Forwarded-Host", request.url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear I am not sure that X-Forwarded-Host is the correct thing here. It is what I was thinking of but I think is only for hosts not full URLs.

Do you have a requirement for this header on the server?
What is the header it is looking for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm writing the server part as well, so we are free to decide what we like best 😄
the only requirement i have is for this local fetcher to send the full path and query string to the server, so any header name does the job

@petebacondarwin
Copy link
Contributor

Still LGTM!

@petebacondarwin petebacondarwin merged commit 31729ee into cloudflare:main Nov 22, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants