» How do I get the content length of a Django response object?
How do I get the content length of a Django response object?
|April 5, 2011
Posted by forumadmin
In Django, I try to logging the request and response content length, which exactly the same as what Django server prints to stderr.
[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
So, I write a simple middleware as follows, but, the value of ‘Content-Length’ is always empty.
def process_response(self, request, response):
time_text = datetime.datetime.now().strftime('%m/%d/%Y %H:%M:%S')
print '[%s] "%s %s" %d %s' % (time_text, request.method, request.path,
I’ve checked through fire-debug, there is ‘Content-Length’ in the response headers. But there is no ‘Content-Length’ in the middleware, “print response.items()” shows:
[('Content-Type', 'text/html; charset=utf-8')]
Is there any problem of the middleware orders?
More Related Questions
- .NET: Simplest way to send POST with data and read response To my surprise, I can't do anything nearly as simple as this, from what I can tell, in the .NET BCL:
byte response = Http.Post
- Get only 1k bytes from HTTP Response I'm currently do PHP Curl connection and I want to retrieve only the first 1k bytes of the Http Response. The server probably not accept Range-Bytes. Do you know some other way? […]
- Get Size of HTTP Response in Java I would like to know how much data was sent in response to a certain http-request.
What I currently do is this:
HttpURLConnection con = (HttpURLConnection) […]
- what is relation between content-length and byte ranges in HTTP/1.1? I am not grasping the idea behind content-length and byte ranges as specified by HTTP 1.1
Is there are connection between the two of some sort? If a client requests in terms of byte […]
- How to reflect change in ap_release.h in existing apache without make install I have downloaded Apache 2.2.17 and changed the ap_release.h file. So instead of Server: Apache in http response I can return some other information.
Then I ran ./configure and then make. […]
- What is the maximum length of a URL in different browsers? What is the maximum length of a URL in different browsers? Does it differ between browsers?
Does the HTTP protocol dictate it? Asked By - Sander […]
- Content-Length header not returned from Pylons response I'm still struggling to Stream a file to the HTTP response in Pylons. In addition to the original problem, I'm finding that I cannot return the Content-Length header, so that for large […]
- Content-Length header versus chunked encoding I'm trying to weigh the pros and cons of setting the Content-Length HTTP header versus using chunked encoding to return [possibly] large files from my server. One or the other is needed […]
- Prevent Django from blocking while proxying an HTTP request I'm working on a Django site that allows connecting to devices in restricted networks through a cloud service. The devices connect to a cloud server through a VPN or SSH tunnel and clients […]
- problems with ldap authentication in django I'm need your helps in my project.
I have site with login from ldap server, i'm do this, and in my local machine it's working, working as well but slowly, so first question why login so […]