https://kotlinlang.org logo
#ktor
Title
# ktor
m

Mike Dawson

10/26/2023, 5:59 PM
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: https://youtrack.jetbrains.com/issue/KTOR-3242 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?
e

e5l

10/27/2023, 1:14 PM
Hey @Mike Dawson, Thanks for the bump! I’ll check the original issue
m

Mike Dawson

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.
e

e5l

10/27/2023, 2:44 PM
Could you try if you can disable compression on the Ktor side?
m

Mike Dawson

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
... Which is the full uncompressed size of the file being served. We definitely don't want to serve Javascript, CSS, etc. without gzipping it, so then we can handle the compression in Apache.
e

e5l

10/27/2023, 2:47 PM
I see, thank you