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

fix: try to serve assets from unencoded and encoded paths #6728

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

emily-shen
Copy link
Contributor

What this PR solves / how to test

Fixes WC-2693

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: no relevant e2es yet :(
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Changeset included
    • Changeset not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: unreleased feat

@emily-shen emily-shen requested a review from a team as a code owner September 16, 2024 19:53
Copy link

changeset-bot bot commented Sep 16, 2024

⚠️ No Changeset found

Latest commit: 6416648

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Copy link
Contributor

github-actions bot commented Sep 16, 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/10936309370/npm-package-wrangler-6728

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

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

Or you can use npx with this latest build directly:

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

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.20240909.3
workerd 1.20240909.0 1.20240909.0
workerd --version 1.20240909.0 2024-09-09

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

@emily-shen emily-shen marked this pull request as draft September 16, 2024 20:07
Copy link
Member

Choose a reason for hiding this comment

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

Love these changes. Will make it much easier for WfP/API users.

Copy link
Member

Choose a reason for hiding this comment

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

cool. nicely broken down :)

// exact matches should win
{
title: "/[boop] -> 200 (with /[boop].html)",
files: ["/%5Bboop%5D.html", "/[boop].html"],
Copy link
Member

Choose a reason for hiding this comment

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

Since we're now asking clients to always just upload unencoded, and we always serve at the encoded path, why do we end up having ambiguity in which to serve? If they upload something like /[boop].html and also /%5Bboop%5D.html, can we not just understand that the first should be served at /%5Bboop%5D and the later should be served at /%255Bboop%255D (double-encoded)?

Copy link
Contributor Author

@emily-shen emily-shen Sep 17, 2024

Choose a reason for hiding this comment

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

If only /%5Bboop%5D.html existed, would that still be served at /%255Bboop%255D only and /%5Bboop%5D should redirect? And similarly /bin%2F only at /bin%252F?

(these are niche enough that I don't have any strong opinions either way, just want to clarify expected behaviour!)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, needed to think about this for a while. I think that's what I'd (intellectually) lean towards, yeah — if they want to serve it at some other location, they need to encode it however they want to at upload — but you make a pretty good point with that example. I'd be surprised, but being that "strict" may break the expectation of some other people/frameworks, I simply don't know for sure.

We've validated that this PR in it's current state makes Michael happy, so I'd say we should just proceed with this for now. If you have time, maybe cook up another version which does "/%5Bboop%5D.html at /%255Bboop%255D only" and we can evaluate if we want to make that change separately? I think it might allow you to simplify the asset serving logic a fair bit — it makes us more consistent and deterministic.

Interestingly, having now written a bunch of additional test cases for this PR, I've discovered this seems to only be an issue for auto-trailing-slash somehow. Can't quite wrap my brain around why that is, but yeah, that seems to be the behavior right now.

Copy link
Contributor Author

@emily-shen emily-shen Sep 19, 2024

Choose a reason for hiding this comment

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

If you have time, maybe cook up another version which does "/%5Bboop%5D.html at /%255Bboop%255D only" and we can evaluate if we want to make that change separately? I think it might allow you to simplify the asset serving logic a fair bit — it makes us more consistent and deterministic.

I actually tried this out the other day, and indeed it does make the logic a lot simpler. I've chucked that on a branch here: https://github.com/cloudflare/workers-sdk/tree/double-encode

fixtures/asset-config/test-cases/encoding-test-cases.ts Outdated Show resolved Hide resolved
// exact matches should win
{
title: "/[boop] -> 200 (with /[boop].html)",
files: ["/%5Bboop%5D.html", "/[boop].html"],
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, needed to think about this for a while. I think that's what I'd (intellectually) lean towards, yeah — if they want to serve it at some other location, they need to encode it however they want to at upload — but you make a pretty good point with that example. I'd be surprised, but being that "strict" may break the expectation of some other people/frameworks, I simply don't know for sure.

We've validated that this PR in it's current state makes Michael happy, so I'd say we should just proceed with this for now. If you have time, maybe cook up another version which does "/%5Bboop%5D.html at /%255Bboop%255D only" and we can evaluate if we want to make that change separately? I think it might allow you to simplify the asset serving logic a fair bit — it makes us more consistent and deterministic.

Interestingly, having now written a bunch of additional test cases for this PR, I've discovered this seems to only be an issue for auto-trailing-slash somehow. Can't quite wrap my brain around why that is, but yeah, that seems to be the behavior right now.

matchedFile: "/%5Bboop%5D.html",
finalPath: "/%5Bboop%5D",
},
// mix of encoded and unencoded paths
Copy link
Member

Choose a reason for hiding this comment

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

Great that we can handle this!

@emily-shen emily-shen force-pushed the emily/redirect-to-encoded branch 2 times, most recently from 9ff1521 to b31019a Compare September 19, 2024 20:28
@emily-shen emily-shen marked this pull request as ready for review September 19, 2024 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants