I want to control the Content-Length and Transfer-Encoding header for an http file download endpoint. I want to ensure that clients can see the Content-Length (so they know how much needs downloaded), and use gzip (to minimize the size). I'm planning on storing most of the files gzipped on disk anyway.
As per this issue:
It's not allowed to set that header. The ContentEncoder interface does not support reporting on the output size (which, in my case, I already know because the file is stored gzipped): https://ktor.io/docs/content-encoding.html#install_plugin
When I used the encoding plugin, the content-length is not specified and chunked encoding is used.
Is there something I'm missing that would allow controlling transfer encoding?
10/27/2023, 1:14 PM
Hey @Mike Dawson, Thanks for the bump! I’ll check the original issue
10/27/2023, 2:43 PM
Thank you @e5l - thank you for checking that out. Would be great if this limitation can be removed.
i think in most production situations, ktor would be behind an Nginx or Apache reverse proxy. In that case, one can allow the reverse proxy to take care of doing gzip. In my case it means a static file (stored gzipped), will be inflated by ktor, then deflated again by Apache, not the most efficient thing, but it will still work. I'll comment on the issue.
10/27/2023, 2:44 PM
Could you try if you can disable compression on the Ktor side?
10/27/2023, 2:46 PM
I have - if I don't use the compression plugin on the ktor side, then the response comes back with the expected content-length header