š BUG: Content-Length header missing from worker response when Content-Type present
See original GitHub issueWhat 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.
- 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" : "", }, }); }, };
- Run:
wrangler dev src/index.ts
- 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:
- Created a year ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?
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:
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:
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.