Skip to content

fix(playground-preview-worker,edge-preview-authenticated-proxy): ensure no body is passed when constructing a GET or HEAD request to the preview worker#7793

Merged
edmundhung merged 6 commits intomainfrom
edmundhung/fix-get-raw-http-request
Jan 27, 2025
Merged

fix(playground-preview-worker,edge-preview-authenticated-proxy): ensure no body is passed when constructing a GET or HEAD request to the preview worker#7793
edmundhung merged 6 commits intomainfrom
edmundhung/fix-get-raw-http-request

Conversation

@edmundhung
Copy link
Copy Markdown
Member

@edmundhung edmundhung commented Jan 16, 2025

Fixes #7791, #7630

This PR fixes the following error we see after releasing the change on #7639.

Error: Request with a GET or HEAD method cannot have a body.

The implementation has been updated in both playground-preview-worker and edge-preview-authenticated-proxy, which are used by the worker playground and the dashboard.

Note: This change itself will not affect how playground and dashboard works as the behavior is opt-in. We will have to un-revert #7639 and we should be able to verify this on the preview playground.


  • 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:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 795620c

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

This PR includes changesets to release 2 packages
Name Type
edge-preview-authenticated-proxy Patch
playground-preview-worker 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 16, 2025

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/12929815285/npm-package-wrangler-7793

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-wrangler-7793 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-workers-bindings-extension-7793 -O ./cloudflare-workers-bindings-extension.0.0.0-v7ffe58091.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v7ffe58091.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-create-cloudflare-7793 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-kv-asset-handler-7793

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-miniflare-7793

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-pages-shared-7793

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-unenv-preset-7793

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-vite-plugin-7793

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-vitest-pool-workers-7793

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-workers-editor-shared-7793

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-workers-shared-7793

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12929815285/npm-package-cloudflare-workflows-shared-7793

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


wrangler@3.105.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20241230.2
workerd 1.20241230.0 1.20241230.0
workerd --version 1.20241230.0 2024-12-30

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

@edmundhung edmundhung changed the title fix(playground-preview-worker,edge-preview-authenticated-proxy): ensure X-CF-Http-Method header works with GET fix(playground-preview-worker,edge-preview-authenticated-proxy): ensure no body is passed when constructing a GET or HEAD request to the preview worker Jan 16, 2025
@edmundhung edmundhung force-pushed the edmundhung/fix-get-raw-http-request branch from beea6fa to d7dc19c Compare January 16, 2025 14:45
@edmundhung edmundhung marked this pull request as ready for review January 16, 2025 14:49
@edmundhung edmundhung requested a review from a team as a code owner January 16, 2025 14:49
@edmundhung edmundhung added the e2e Run wrangler + vite-plugin e2e tests on a PR label Jan 16, 2025
expect(await resp.text()).toEqual("PUT");
});

it.each(["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"])(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❤️ 🙏 🚀

@edmundhung edmundhung force-pushed the edmundhung/fix-get-raw-http-request branch from d7dc19c to 795620c Compare January 23, 2025 13:05
@lrapoport-cf lrapoport-cf added the caretaking Priority for caretaking label Jan 25, 2025
Comment on lines +85 to +88
method,
headers,
body: method === "GET" || method === "HEAD" ? null : request.body,
redirect: "manual",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have checked which properties we can pass here and it looks like only these 4 are relevant. But if you think differently, please let me know 👍🏼

async (method) => {
const token = randomBytes(4096).toString("hex");
const resp = await worker.fetch(
`https://0000.rawhttp.devprod.cloudflare.dev/method`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's the reason for testing a remote worker here? Can we just use Miniflare for this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It is local 👍🏼 . We are running two separate instances through unstable_dev to mimick proxy <-> remote communication:

worker = await unstable_dev(path.join(__dirname, "../src/index.ts"), {
// @ts-expect-error TODO: figure out the right way to get the server to accept host from the request
host: "0000.rawhttp.devprod.cloudflare.dev",
ip: "127.0.0.1",
experimental: {
disableExperimentalWarning: true,
},
});
tmpDir = await fs.realpath(
await fs.mkdtemp(path.join(os.tmpdir(), "preview-tests"))
);
await fs.writeFile(
path.join(tmpDir, "remote.js"),
/*javascript*/ `
export default {
fetch(request) {
const url = new URL(request.url)
if(url.pathname === "/exchange") {
return Response.json({
token: "TEST_TOKEN",
prewarm: "TEST_PREWARM"
})
}
if(url.pathname === "/redirect") {
return Response.redirect("https://example.com", 302)
}
if(url.pathname === "/method") {
return new Response(request.method, {
headers: { "Test-Http-Method": request.method },
})
}
if(url.pathname === "/status") {
return new Response(407)
}
if(url.pathname === "/header") {
return new Response(request.headers.get("X-Custom-Header"))
}
if(url.pathname === "/cookies") {
const headers = new Headers();
headers.append("Set-Cookie", "foo=1");
headers.append("Set-Cookie", "bar=2");
return new Response(undefined, {
headers,
});
}
return Response.json({
url: request.url,
headers: [...request.headers.entries()]
}, { headers: { "Content-Encoding": "identity" } })
}
}
`.trim()
);
await fs.writeFile(
path.join(tmpDir, "wrangler.toml"),
/*toml*/ `
name = "remote-worker"
compatibility_date = "2023-01-01"
`.trim()
);
remote = await unstable_dev(path.join(tmpDir, "remote.js"), {
config: path.join(tmpDir, "wrangler.toml"),
ip: "127.0.0.1",
experimental: { disableExperimentalWarning: true },
});

Copy link
Copy Markdown
Contributor

@andyjessop andyjessop left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@edmundhung edmundhung merged commit 9941219 into main Jan 27, 2025
@edmundhung edmundhung deleted the edmundhung/fix-get-raw-http-request branch January 27, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

caretaking Priority for caretaking e2e Run wrangler + vite-plugin e2e tests on a PR

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants