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

🐛 BUG: wrangler dev switches Accept-Encoding and request.cf.clientAcceptEncoding #5246

Closed
thomastoye opened this issue Mar 14, 2024 · 1 comment · Fixed by #5409 or #5582
Closed
Labels
bug Something that isn't working

Comments

@thomastoye
Copy link

Which Cloudflare product(s) does this pertain to?

Workers Runtime

What version(s) of the tool(s) are you using?

3.34.0 (wrangler)

What version of Node are you using?

18.16.1

What operating system and version are you using?

Ubuntu 20.04.6 LTS 5.4.0-173-generic x86_64

Describe the Bug

Observed behavior

Difference between wrangler dev and deployed Cloudflare Worker in request.headers.get('accept-encoding') and request.cf.clientAcceptEncoding.

curl -H 'Accept-Encoding: hello' https://shy-leaf-70f4.***.workers.dev/:

accept: */*
accept-encoding: gzip, br <-------
cf-connecting-ip: ******
cf-ipcountry: BE
cf-ray: *********
cf-visitor: {"scheme":"https"}
connection: Keep-Alive
host: shy-leaf-70f4.***.workers.dev
user-agent: curl/7.86.0
x-forwarded-proto: https
x-real-ip: ******

Client accept encoding: hello <-------

curl -H 'Accept-Encoding: hello' localhost:8787 (wrangler dev):

accept: */*
accept-encoding: hello <-------
host: localhost:8787
user-agent: curl/7.86.0

Client accept encoding: br, gzip, deflate <-------

See https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#accept-encoding

For incoming requests, the value of this header will always be set to accept-encoding: br, gzip. If the client set a different value, such as accept-encoding: deflate, it will be overwritten and the original value will be available in request.cf.clientAcceptEncoding.

The local case is incorrect: The client provided Accept-Encoding: hello, so request.cf.clientAcceptEncoding should be hello and accept-encoding on the headers should be br, gzip or gzip, br as in the documentation.

Expected behavior

curl -H 'Accept-Encoding: hello' https://shy-leaf-70f4.***.workers.dev/:

accept: */*
accept-encoding: gzip, br <-------
cf-connecting-ip: ******
cf-ipcountry: BE
cf-ray: *********
cf-visitor: {"scheme":"https"}
connection: Keep-Alive
host: shy-leaf-70f4.***.workers.dev
user-agent: curl/7.86.0
x-forwarded-proto: https
x-real-ip: ******

Client accept encoding: hello <-------

curl -H 'Accept-Encoding: hello' localhost:8787 (wrangler dev):

accept: */*
accept-encoding: gzip, br <-------
host: localhost:8787
user-agent: curl/7.86.0

Client accept encoding: hello <-------

Steps to reproduce

A minimal working subset of your worker code

export default {
	async fetch(request, env, ctx) {
		return new Response(
			[...request.headers].map(h => h.join(': ')).join('\n') + '\n\n' +
			`Client accept encoding: ${request.cf.clientAcceptEncoding}`,
			{ headers: { 'Content-Type': 'text/plain' } }
		)
	},
};

A minimal working subset of your wrangler.toml

name = "shy-leaf-70f4"
main = "src/index.js"
compatibility_date = "2024-03-12"

Commands used to start your local dev server, including custom env and cli args

wrangler dev and wrangler deploy. Nothing special.

Steps to be performed in the browser, curl commands, or a test we can run that reliably fails (at least a percent of the time)

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

@mrbbot
Copy link
Contributor

mrbbot commented Mar 27, 2024

Hey! 👋 Thanks for raising this. I've put up a PR that should fix this issue (#5409). Would you be able to try out the pre-release (#5409 (comment)) and confirm this fixes things for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working
Projects
None yet
2 participants