question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

šŸ› BUG: Content-Length header missing from worker response when Content-Type present

See original GitHub issue

What version of Wrangler are you using?

2.0.24

What operating system are you using?

Mac

Describe the Bug

When running wrangler dev, the Content-Length header is missing from responses if the Content-Type header is present and the Content-Length value is greater than "47".

Reproduce the bug

A list of steps to reproduce the bug.

  1. Create src/index.ts:
    // src/index.ts
    export default {
      async fetch(request: Request): Promise<Response> {
        const query = new URL(request.url).searchParams;
        const contentLength = query.get("length") || "0";
        const useContentType = !query.has("no-content-type");
    
        return new Response(null, {
          headers: {
            "content-length": contentLength,
            "content-type": useContentType ? "text/plain" : "",
          },
        });
      },
    };
    
  2. Run:
    wrangler dev src/index.ts
    
  3. Test headers:
    curl --head "http://localhost:8787?length=47" # Should see content-length & content-type header
    curl --head "http://localhost:8787?length=48" # Will see only see content-type header
    curl --head "http://localhost:8787?length=48&no-content-type" # Will only see content-length
    
Example responses
āž¤ curl --head "http://localhost:8787?length=47"
HTTP/1.1 200 OK
date: Tue, 04 Oct 2022 01:56:18 GMT
content-type: text/plain
content-length: 47
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=0DzkIHu1Lq67UVp%2F3C6xjrLmoYA8hemI0R8ljz3tvi7u9myGZ%2BVkt%2FdFIeM3WKpPafwGrEAgY7H3ruK4t91qmfhDYUYH1iwZ%2Bw3z4lIESO4fP276c61m8SpV81EwTLMJGWajRXlu0IvBudGEdrjDAnI0Vt9qSEDT7tNy9r9%2F4oBG"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-ray: 754a4ce1befe8419-YVR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
server: cloudflare
Connection: keep-alive
Keep-Alive: timeout=5

āž¤ curl --head "http://localhost:8787?length=48"
HTTP/1.1 200 OK
date: Tue, 04 Oct 2022 01:56:24 GMT
content-type: text/plain
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=SRSFjjRgbee0eBWHfBA7HRXPYIyWWuiXF7SjH493J7jfTz7OsdT6TskyZ%2BIR6u7F2o1Y3UtpHHKhYGnYFFEPH4bNv7JuOXQliDbRjDkfy0%2BC7KIamVJWlYB7aGXO4PxSLL24tcY1pD0RgawhKFOA%2B4Gf8SSFfrfTQgWIhWFo6MzX"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-ray: 754a4d027d628419-YVR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
server: cloudflare
Connection: keep-alive
Keep-Alive: timeout=5

āž¤ curl --head "http://localhost:8787?length=48&no-content-type"
HTTP/1.1 200 OK
date: Tue, 04 Oct 2022 01:56:33 GMT
content-length: 48
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=TFg3iX90nLT%2FuAJsytKW9Y1WjbxmomkByaoO1y6lHBTgxt8YReSIXFPdpg84SMuJgziKoGgGr4gDmosML9L6%2Ft3cq7vh%2BglfWpPs9p0q8xUJncc9VJ%2FOFjtSyYpu5PHoF%2B67Omh6rwB%2FMFsZZ9sWlnqNGB%2B0%2FGObC1rLfUD0i1L5"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-ray: 754a4d3f8af18419-YVR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
server: cloudflare
Connection: keep-alive
Keep-Alive: timeout=5

Work Around

As discovered in the Cloudflare community forum, this behaviour can be avoided by running wrangler dev with the --local flag (wrangler dev --local).

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
penalosacommented, Oct 7, 2022

I initially couldnā€™t reproduce it, but I think I can now trigger it intermittently. Weā€™ll follow up internally to see what might be causing this (and thanks for the detailed reproduction steps), but in the meantime, would you be able to provide any more details on your original use case? Perhaps thereā€™s a workaround that we could help with?

0reactions
alukachcommented, Oct 9, 2022

would you be able to provide any more details on your original use case?

My use-case is that I am developing an API that is required to send the content-length header in response to HEAD requests. Downstream clients throw errors if this header is not present in the responses.

I note that others have been able to reproduce this issue:

Perhaps thereā€™s a workaround that we could help with?

As mentioned in the original comment, this can be avoided by running Wrangler dev with the --local flag, so Iā€™m not currently blocked.


I donā€™t think this is an emergency or top priority, but would argue that this bug:

  1. demonstrates a small level of instability on the part of wranglerā€™s dev server, which adds to a developerā€™s cognitive load when developing applications with Wrangler2
  2. can be a bit of a time suck for future developers who are developing applications and burn a number of hours trying to figure out why their API clients are not properly interacting with their local Wrangler-dev-hosted API.

As an aside, I will mention that my experience with Wrangler2 has been great and Iā€™m having a fun time onboarding to Cloudflare Workers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Worker: Content-Length header missing when Content-Type ...
I expect the content-length header to be present in both responses. This is what occurs when the Worker is actually deployed to Cloudflare....
Read more >
Content-Length header missing when Content-Type present
I've noticed that when I set the Content-Type header on a response, the Content-Length value is missing. I'm experiencing this usingĀ ...
Read more >
Missing Content-Length header sending POST request with ...
I'm using WebClient (SpringBoot 2.0.2.RELEASE) to send a POST with SOAP request, but it is missing "Content-Length" header required by theĀ ...
Read more >
HTTP Callout fails with 'Content-Length is missing' error
While invoking a HTTP Callout, 'Content-Length is missing' error is observed. The content length header is missing. If size of the entity bodyĀ ......
Read more >
Accept-Encoding - HTTP - MDN Web Docs
The Accept-Encoding request HTTP header indicates the content encoding (usually a compression algorithm) that the client can understand.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found