How to Disable Chunked Transfer Encoding in Apache for HTTP/1.1 Responses


2 views

When dealing with Server Side Includes (SSI) on Apache, some developers encounter issues when the server automatically applies Transfer-Encoding: chunked for HTTP/1.1 clients. This typically manifests as corrupted output when:

  • Using mod_include with dynamic content
  • Running on Solaris systems with sendfile() enabled
  • Serving to HTTP/1.1 clients while working fine for HTTP/1.0

The core issue stems from Apache's default behavior of chunking responses when:

Content-Length header is absent
AND
HTTP version is 1.1
AND
sendfile optimization is enabled

Here are three approaches to resolve this:

1. Force Content-Length Calculation

Add this to your Apache configuration:


<FilesMatch "\.shtml$">
    SetOutputFilter INCLUDES
    ContentDigest On
</FilesMatch>

2. Disable sendfile() Specifically

For Solaris systems, disable sendfile in httpd.conf:


EnableSendfile off

3. Override Chunked Encoding

Create a custom output filter:


<Location "/ssi-content/">
    SetOutputFilter INCLUDES;DEFLATE
    RequestHeader unset Accept-Encoding
</Location>

After implementing changes, verify with:


curl -I -H "Host: yourdomain.com" http://localhost/path/to/ssi.shtml

Look for either Content-Length header appearing or Transfer-Encoding: chunked disappearing from the response headers.

While these solutions work, be aware that:

  • Disabling sendfile() may impact performance for large static files
  • Calculating Content-Length adds minor CPU overhead
  • The best approach depends on your specific content mix and traffic patterns

When working with Server Side Includes (SSI) on Apache servers, you might encounter output corruption when the server automatically applies Transfer-Encoding: chunked for HTTP/1.1 clients. This particularly manifests on Solaris 10 SPARC systems with sendfile() enabled.

The key symptoms include:

# Correct output with HTTP/1.0:
curl -0 http://example.com/ssi_page.shtml

# Corrupted output with HTTP/1.1:
curl http://example.com/ssi_page.shtml

Option 1: Disable Chunked Encoding for Specific Files

<FilesMatch "\.shtml$">
    SetEnv no-chunked-encoding 1
</FilesMatch>

Option 2: Force Content-Length Headers

# In httpd.conf or virtual host
SetEnv proxy-sendcl 1
SetEnv proxy-sendchunked 0

For Solaris systems where sendfile() causes the issue:

# Disable sendfile completely
EnableSendfile off

# Or disable just for SSI files
<FilesMatch "\.shtml$">
    EnableSendfile Off
</FilesMatch>

Verify the solution with:

curl -v http://example.com/test.shtml | grep -i "Transfer-Encoding"

The output should not show "chunked" in the response headers.

While disabling chunked encoding solves the SSI issue, be aware that:

  • This prevents HTTP/1.1 pipelining for affected resources
  • Large files will buffer completely before sending
  • Consider applying the fix only to SSI files, not globally