Ticket #5898: middleware.http.patch

File middleware.http.patch, 938 bytes (added by Scott Barr <scott@…>, 16 years ago)

Patch

  • http.py

     
    5757            # client's IP will be the first one.
    5858            real_ip = real_ip.split(",")[0].strip()
    5959            request.META['REMOTE_ADDR'] = real_ip
     60
     61class HeadMiddleware(object):
     62    """ Make a sensible HEAD response """
     63
     64    def process_response(self, request, response):
     65        """
     66        If the request method is HEAD and the response is 200 OK, set the
     67        'Content-Length' header, and remove the content body.
     68        """
     69        if request.method == 'HEAD':
     70            # set the Content-Length header if not already set
     71            if not response.has_header('Content-Length'):
     72                response['Content-Length'] = str(len(response.content))
     73
     74            # remove the content
     75            response.content = ''
     76
     77        return response
Back to Top