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

[miniflare] feature: respect incoming Accept-Encoding header #5409

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Mar 27, 2024

What this PR solves / how to test

Fixes #5246 (CUSTESC-39344).

This PR updates Miniflare to respect the incoming Accept-Encoding header, and set the correct value of Accept-Encoding/request.cf.clientAcceptEncoding inside the Worker. This is to match the production/documented behaviour here: https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#accept-encoding.

Author has addressed the following

@mrbbot mrbbot requested a review from a team as a code owner March 27, 2024 11:38
Copy link

changeset-bot bot commented Mar 27, 2024

🦋 Changeset detected

Latest commit: 18ac0fa

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

This PR includes changesets to release 4 packages
Name Type
miniflare Minor
@cloudflare/pages-shared Patch
@cloudflare/vitest-pool-workers Patch
wrangler 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 Mar 27, 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/8629582197/npm-package-wrangler-5409

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

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

Or you can use npx with this latest build directly:

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

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


wrangler@3.48.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240404.0
workerd 1.20240404.0 1.20240404.0
workerd --version 1.20240404.0 2024-04-04

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

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.28%. Comparing base (2789f26) to head (bcb298e).
Report is 7 commits behind head on main.

❗ Current head bcb298e differs from pull request most recent head 18ac0fa. Consider uploading reports for the commit 18ac0fa to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5409      +/-   ##
==========================================
- Coverage   72.44%   72.28%   -0.17%     
==========================================
  Files         331      322       -9     
  Lines       17298    16663     -635     
  Branches     4422     4260     -162     
==========================================
- Hits        12532    12045     -487     
+ Misses       4766     4618     -148     

see 94 files with indirect coverage changes

@petebacondarwin petebacondarwin self-assigned this Apr 9, 2024
@petebacondarwin petebacondarwin added the e2e Run e2e tests on a PR label Apr 10, 2024
@petebacondarwin petebacondarwin merged commit 08b4908 into main Apr 11, 2024
20 checks passed
@petebacondarwin petebacondarwin deleted the bcoll/respect-accept-encoding branch April 11, 2024 09:32
@frandiox
Copy link

@mrbbot Hey 👋 I understand this is a fix but it actually creates a breaking change for those proxying Miniflare in Node.js. It works in miniflare@3.20240405.0 but breaks in miniflare@3.20240405.1. Just mentioning it in case you want to document it in the changelog or somewhere:

Running mf.dispatchFetch(...) (or plain fetch(workerUrl)) is decompressing the response but keeping Content-Encoding: gzip or similar in the response headers. Then, once we forward this response from Node (e.g. Vite server) to the browser, the browser expects encoded content but it is not encoded anymore.

Unfortunately, I think there's no way to avoid decompressing the response in undici. The workaround is to remove Content-Encoding from the Miniflare response or recompressing it in Node -- or perhaps use Node's http.get instead of fetch to get the response... which is not intuitive with mf.dispatchFetch().

Related:

cc @hi-ogawa probably relevant for your plugins if you update to miniflare@3.20240405.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: wrangler dev switches Accept-Encoding and request.cf.clientAcceptEncoding
3 participants