How can I disable Transfer-Encoding: chunked in Apache with HTTP/1.1 responses

Solution 1:

If you pre-specify Content-length, Apache won't have to use chunked. Without Content-length, Apache has no option but to use it.

To be clear: HTTP/1.0 manages it because Apache reads in the entire response before sending it along, so it know how large it'll be. This is hilariously inefficient, and slow, and AFAIK there's no way to enable this logic for HTTP/1.1 requests, except by forcing them to HTTP/1.0 (which you really, really don't want to do, do you? If you do, the environment variable to set is "downgrade-1.0")

Solution 2:

The above answer is incorrect.

If request is HTTP/1.0, Apache never buffers the response before sending it (with Content-Length header). Of course Apache could do that, but there is more elegant solution that Apache uses: it responds with "Connection: close" header and closes connection as soon as it sends all the data.

According to HTTP spec, the presence of "Connection: close" header means the client needs to read till connection is closed.

The solution to your problem is to force Apache treat the request as HTTP/1.0 by setting the mentioned downgrade-1.0 environment variable. The chunked Transfer-Encoding is a HTTP/1.1 feature, and Apache won't use it for HTTP/1.0 request.

E.g. here is how you could disable chunked responses for php files:

++++++++++++
apache.conf
++++++++++++

<Files *.php>
    SetEnv downgrade-1.0
</Files>