Ticket #5898: middleware.http.2.patch

File middleware.http.2.patch, 940 bytes (added by Scott Barr <scott@…>, 17 years ago)
  • 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        It is expected that CommonMiddleware has already processed the response
     70        and added the Content-Length header, which is desirable in the response
     71        to a HEAD request.
     72        """
     73        if request.method == 'HEAD':
     74            # remove the content
     75            response.content = ''
     76
     77        return response
Back to Top