title: Apache sending Transfer-Encoding: chunked when deflate module is enabled
body: <p>I have a simple web.py code like below, deployed with mod_wsgi in apache.</p>
  
  <pre class="lang-py prettyprint-override"><code>import web
  
  urls = (
      '/', 'index'
  )
  
  class index:
      def GET(self):
          content = 'hello'
          web.header('Content-length', len(content))
          return content
  
  app = web.application(urls, globals())
  application = app.wsgifunc()
  </code></pre>
  
  <p>This website runs well, except one minor issue. When mod_deflate is turn on, the response is chunked, even it has a very small response body.</p>
  
  <p>Response Header</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Wed, 20 May 2015 20:14:12 GMT
  Server: Apache/2.4.7 (Ubuntu)
  Vary: Accept-Encoding
  Content-Encoding: gzip
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Transfer-Encoding: chunked
  Content-Type: text/html
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/eAZRX.png" alt="deflate is turn on"></p>
  
  <p>When mod_deflate is <strong>turn off</strong>, <code>Content-Length</code> header is back.</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Wed, 20 May 2015 20:30:09 GMT
  Server: Apache/2.4.7 (Ubuntu)
  Content-Length: 5
  Keep-Alive: timeout=5, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=utf-8
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Ld2pE.png" alt="deflate is turn off"></p>
  
  <p>I've searched around and someone said reduce the <a href="http://httpd.apache.org/docs/2.2/mod/mod_deflate.html#DeflateBufferSize" rel="nofollow noreferrer">DeflateBufferSize</a> will help, but this response's size is only 5, far from it's default value: 8096, so I don't think it interferes with this issue.</p>
  
  <p>And someone said apache send chunked response because it doesn't know the response's size before begin to send the response to client, but in my code, I do set Content-Length.</p>
  
  <p>I've also tried <a href="http://flask.pocoo.org" rel="nofollow noreferrer">Flask</a> and Apache/2.2.15 (CentOS), same result.</p>
  
  <p>How do I set content-length when deflate module is enabled? and I don't like to gzip content in python.</p>