Closed gsimko closed 7 months ago
Thanks for reporting! Would you like to send a Pull Request to address this issue? Remember to add unit tests.
This feature would be a good addition, and it would be even better if we could do it for uncompressed files as well (by using statSync or something)
Looks like this is not a fastify problem. Fastify-static relies on fastify-send and that one already sets content-length by using stat. By locally running the query and checking the response I could confirm that it's set.
In my case it must be some other component that's causing the trouble. I noticed that the browser uses http2 requests while I configured fastify to use http1 so there must be a proxy somewhere in the setup doing the conversion. I guess that one drops the content-length header. @gurgunday could that explain why you also observed this problem?
That's interesting, I don't see the header in my production app either, let me try on localhost and come back on this
Oh yeah, it's compress
that's removing it for me, which makes sense
It might indeed be a proxy like Cloudflare that's dropping it too
Closing the issue if you don't have any other problems, feel free to comment again otherwise
Prerequisites
🚀 Feature Proposal
I propose to set content-length when it's available. I'm using the preCompressed option so the size is trivially available. I'm less certain whether it is doable for on-the-fly encoding. Wdyt?
Motivation
No response
Example
No response