-
Notifications
You must be signed in to change notification settings - Fork 742
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
Remove incorrect logic in Asset Worker #7176
Conversation
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/12011975582/npm-package-wrangler-7176 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7176/npm-package-wrangler-7176 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-wrangler-7176 dev path/to/script.js Additional artifacts:npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-create-cloudflare-7176 --no-auto-update npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-cloudflare-kv-asset-handler-7176 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-miniflare-7176 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-cloudflare-pages-shared-7176 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-cloudflare-vitest-pool-workers-7176 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-cloudflare-workers-editor-shared-7176 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-cloudflare-workers-shared-7176 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12011975582/npm-package-cloudflare-workflows-shared-7176 Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
@@ -129,10 +125,6 @@ export default class extends WorkerEntrypoint<Env> { | |||
}, | |||
this.unstable_exists.bind(this) | |||
); | |||
// if asset exists but non GET/HEAD method, 405 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might still want this check in router worker, since we would rather return the user worker instead of a 405. I'm totally in agreance this makes sense as just a bool response!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't change that behavior now without a compat flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this makes sense as a boolean; and also that we need to change Router Worker to handle the 405 case.
Also, we could do with more tests on this worker. Currently there are scant few. But perhaps unfair on @jamesopstad to be the one to write those?
@petebacondarwin There are some tests scattered across the fixtures - that should probably be documented somewhere whoops. There actually are some tests for the 405 (in |
@jamesopstad can you please include a changeset to your PR 🙏 ? |
dbb427c
to
7010c78
Compare
🦋 Changeset detectedLatest commit: a311397 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
1e27a60
to
a311397
Compare
When I was looking through the Asset Worker code I spotted an error:
workers-sdk/packages/workers-shared/asset-worker/src/index.ts
Lines 132 to 135 in afe9850
This currently does the opposite of what it should and returns the
MethodNotAllowedResponse
forGET
andHEAD
methods. The only reason that the Router Worker is still functioning correctly is because it treats theMethodNotAllowedResponse
as truthy.workers-sdk/packages/workers-shared/router-worker/src/index.ts
Line 60 in afe9850
I've removed method handling from
unstable_canFetch
altogether as I feel that it should only return a boolean. The Asset Worker already returns aMethodNotAllowedResponse
for methods other thanGET
andHEAD
.workers-sdk/packages/workers-shared/asset-worker/src/handler.ts
Lines 32 to 34 in afe9850
If this also needs to occur earlier then the request method could be checked in the Router Worker.
I haven't added tests as there aren't any others for the Asset Worker beyond the KV store at present.