I propose an option for compression to set the Content-Length header on responses that have been compressed by server.compression.enabled. Since server.compression.min-response-size expects a Content-Length anyway, it would be nice to still have Content-Length after compression is performed.

For context, I am trying to use Spring Cloud Gateway with Google's Cloud CDN caching, which requires Content-Length to be set for caching to be performed.

Comment From: wilkinsona

Thanks for the suggestion, but it isn't possible to include a Content-Length header when the response is being compressed. This is because the size of a compressed response is unpredictable and, short of compressing the entire response in memory and then sending it to the client, there's no way to know what the Content-Length should be. To avoid having to do everything in memory, the embedded containers switch to chunked transfer encoding which allows them to write the compressed response to the client in chunks. As far as I know, none of the embedded containers that Boot supports (Jetty, Netty, Tomcat, and Undertow) provide an option to perform compression in memory and send a Content-Length header.