There's a very old outstanding but in Apache's mod_fastcgi combined with mod_deflate, where the
Content-Length header is not being passed along properly between the FastCGI process (like PHP) and the compression performed by mod_deflate.
The problem occurs when your Apache webserver is running gzip compression via mod_deflate on the content, which is then being passed via mod_fastcgi to an upstream (like PHP) that tries to handle compression as well. In the case of a Drupal system, this can happen when you let Drupal handle gzip-compression via its Performance settings as well as Apache via its mod_deflate module.
And if you search the interwebs, you'll find lots of reports on this;
- Ubuntu: mod_deflate with mod_fastcgi gives wrong content-length header
- Updating mod_fastcgi to work with mod_deflate
- Debian: apache2: mod_deflate with mod_fastcgi gives wrong content-length header
- mod_fastcgi interaction with mod_deflate
These all go way back, to beyond 2010. So it's safe to say, this problem has been around for some time. The suggestions to upgrade to the latest version of FastCGI don't seem to help either, at least not on my test-system.
My current workaround was just to disable
mod_deflate entirely in Apache, and handle the Gzip compression in another service (like Varnish as HTTP cache or in Nginx as my SSL terminator). This is far from pretty, but it got the job done. For now.
If anyone has any clues why mod_deflate together with mod_fastcgi can cause these headaches, I'd love to hear your thoughts and ideas.