title: How do I get the content length of a Django response object?
body: <p>In Django, I try to logging the request and response content length, which exactly the same as what Django server prints to stderr. </p>
  
  <pre><code>[05/Apr/2011 22:59:08] "GET /pages/ HTTP/1.1" 200 332161
  [05/Apr/2011 22:59:15] "GET /pages/12 HTTP/1.1" 301 0
  [05/Apr/2011 22:59:15] "GET /pages/12/ HTTP/1.1" 200 361474
  [05/Apr/2011 22:59:16] "GET /pages/12/load/tags/ HTTP/1.1" 200 13899
  [05/Apr/2011 22:59:16] "GET /pages/12/load/comments/ HTTP/1.1" 200 82
  </code></pre>
  
  <p>So, I write a simple middleware as follows, but, the value of 'Content-Length' is always empty. </p>
  
  <pre><code>class LogHttpResponse(object):
      def process_response(self, request, response):
          import datetime  
          print response.items()
          time_text = datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
          print '[%s] "%s %s" %d %s' % (time_text, request.method, request.path, 
                                        response.status_code, 
                                        response.get('Content-Length', ''))
          return response 
  </code></pre>
  
  <p>I've checked through fire-debug, <strong>there is 'Content-Length' in the response headers</strong>. But there is no 'Content-Length' in the middleware, "print response.items()" shows:</p>
  
  <pre><code>[('Content-Type', 'text/html; charset=utf-8')]
  </code></pre>
  
  <p>Is there any problem of the middleware orders?</p>