Cloudflare decompresses content in web server responses


I’m struggling to get Cloudflare to pass through the response from my endpoints on Render server in a way that keeps content compressed. I’m using Express and it’s compression middleware. It works fine in local environment, and I’ve confirmed that on Render the response headers are the same. So it doesn’t appear to be a case where the compression middleware skips compression because of headers in the request. The JSON payloads in responses are sizable so this is something that needs to be fixed to reduce bandwidth usage and speed up my app.

The client sends accept-encoding: gzip, deflate, br which is changed to accept-encoding: gzip when CF proxies the request to Render server. From what I can dig up in CF docs, this is expected behavior. Which I think should be okay as the compression middleware is still gzipping the content. The content type header is content-type: application/json; charset=utf-8 and that looks correct across the request and response.

My endpoints return the following headers in response:

transfer-encoding: chunked
content-encoding: gzip

After passing through CF, inspecting the response in client shows that content-encoding: gzip is missing and content was already decompressed by the time client received it.

Based on some responses in this post, I’m wondering if I need to remove content-encoding header in my endpoint responses?

Posting an update for anyone else who runs into the same issue. As soon as I added a custom domain to my web service, the issue resolved itself and now responses stay compressed when requests are made to the custom domain.