Content-Length header missing when Content-Type present
See original GitHub issueIt appears that if the Content-Type header is present, Content-Length is not included in the response.
Example:
import { Hono } from "hono";
const app = new Hono();
app.head(
"/test1",
() =>
new Response(null, {
headers: {
"content-length": "987654321",
},
})
);
app.head(
"/test2",
() =>
new Response(null, {
headers: {
"content-type": "application/json",
"content-length": "987654321",
},
})
);
export default app;
➤ curl --head http://0.0.0.0:8787/test1
HTTP/1.1 200 OK
date: Sun, 02 Oct 2022 04:12:37 GMT
content-length: 987654321
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=mvlI0%2BygL44HvQXozzMMpSlAPz8MQFuGN%2BkiepI50MFf8ZROKo0ap5%2F%2BRTTyeGopX2JVBYZOQV1RUnbAEsx9C2PxEkOraY9EMLGOWZXh2ks1oxtIQiIU78RjxDh0rm%2FHb3oKmeLi2KipEw3rzvbJMatR8z0%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-ray: 753a99ce29928405-YVR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
server: cloudflare
Connection: keep-alive
Keep-Alive: timeout=5
➤ curl --head http://0.0.0.0:8787/test2
HTTP/1.1 200 OK
date: Sun, 02 Oct 2022 04:12:43 GMT
content-type: application/json
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=tZy0y%2F%2BRiSD0sxPn4rDKZ%2FkOV665jhNC0HxibfX7rvFOM3rYmIWHmwK7ioQLB8ayyTxHny1wHZlLTNlzBYcY1WP22N271XFiXPwrSl2xqXmNJeLDoJ9TgK%2FbP%2F%2FABAUNxKpCa9CF3ArmSXXl5Zj0rBbUk4w%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
vary: Accept-Encoding
cf-ray: 753a99f4cb5e8405-YVR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
server: cloudflare
Connection: keep-alive
Keep-Alive: timeout=5
I’m scratching my head trying to understand why this would be…
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 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 >Axios: Content-Length header is missing on request headers
we are facing an issue in production that the 'Content-Length' header is not being sent, even if we hard-code it in the headers...
Read more >Content-Length - HTTP - MDN Web Docs
The Content-Length header indicates the size of the message body, in bytes, sent to the recipient.
Read more >The Content-Length header does not exist - Server Fault
I have nginx server installed on Linux. When I send a request with curl, the Content-Length header is missing from the response. The...
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
Thanks all. I have posted this to the Cloudflare Community’s Workers topic, however it was immediately flagged as spam. I’ll update this comment to link to the thread once it passes review.
I think Cloudflare Workers may be automatically overwriting your Content-Length header. This may be somewhat relevant: https://community.cloudflare.com/t/cant-set-content-length-for-get-requests/174487/2
EDIT: Here’s an interesting blog post that goes very in-depth about Cloudflare Workers and some weirdness with the
Content-Length
header. May be worth it to skim through it. https://www.codejam.info/2022/06/empty-body-no-body-http2.html