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

content-length doesn't get updated #148

Closed
lukaszczerpak opened this issue Jan 12, 2022 · 1 comment
Closed

content-length doesn't get updated #148

lukaszczerpak opened this issue Jan 12, 2022 · 1 comment
Labels
behaviour mismatch Different behaviour to Workers runtime

Comments

@lukaszczerpak
Copy link

lukaszczerpak commented Jan 12, 2022

There is a difference in Content-Length header handling in MF v.2. Let's assume the following proof of concept code:

addEventListener('fetch', function(event) {
  event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
  const response = await fetch(`http://origin.example.com/whatever.txt`)
  // eventually we give up on serving original response, and return 403 with empty body
  return new Response("", {
    headers: {
      ...Object.fromEntries(response.headers),
      ...{
        "x-workers-hello": "Hello from Cloudflare Workers"
      }
    },
    status: 403,
    statusText: "Access Denied"
  })
}

We initially go forward but based on some conditional logic, we decide to serve 403 with empty body. The code copies headers from the original response and this is intentional as we want to retain meta information (content-type + some other headers).

Original response contains Content-Length: 1234.
Since we copy all original response headers, the CL one is copied as well.
Now, CF and MF v1.x - they override the CL to 0, MF v2.x doesn't.
When 403 is served with the CL > 0, the user agent is waiting for the payload which never comes in and causes client timeout.

IMO the behavior should be consistent.

@mrbbot mrbbot added behaviour mismatch Different behaviour to Workers runtime v2.1.0 labels Jan 14, 2022
@mrbbot mrbbot closed this as completed in c010add Jan 14, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Jan 14, 2022

Hey! 👋 I've just released version 2.1.0 including a fix for this. You can find the full changelog here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
behaviour mismatch Different behaviour to Workers runtime
Projects
None yet
Development

No branches or pull requests

2 participants