Ticket #5898: http_requirements.diff
File http_requirements.diff, 4.2 KB (added by , 17 years ago) |
---|
-
django/core/handlers/base.py
50 50 51 51 def get_response(self, request): 52 52 "Returns an HttpResponse object for the given HttpRequest" 53 response = self._real_get_response(request)54 return fix_location_header(request, response)55 56 def _real_get_response(self, request):57 53 from django.core import exceptions, urlresolvers 58 54 from django.core.mail import mail_admins 59 55 from django.conf import settings … … 129 125 callback, param_dict = resolver.resolve500() 130 126 return callback(request, **param_dict) 131 127 128 def fix_up_response(self, request, response): 129 "Fix up a response to try and meet basic HTTP requirements." 130 fixes = (fix_location_header, remove_unallowed_response_content) 131 for fix in fixes: 132 response = fix(request, response) 133 return response 134 132 135 def _get_traceback(self, exc_info=None): 133 136 "Helper function to return the traceback as a string" 134 137 import traceback … … 146 149 response['Location'] = request.build_absolute_uri(response['Location']) 147 150 return response 148 151 152 def remove_unallowed_response_content(request, response): 153 """ 154 Removes the content of responses to HEAD requests, and of responses with 155 status codes 1xx (Informational), 204 (No Content), and 304 (Not Modified) 156 that must not have content. This is required by RFC 2616, section 4.3. 157 """ 158 if 100 <= response.status_code < 200 or response.status_code in (204, 304): 159 response.content = '' 160 response['Content-Length'] = 0 161 if request.method == 'HEAD': 162 response.content = '' 163 return response -
django/core/handlers/modpython.py
162 162 # Apply response middleware 163 163 for middleware_method in self._response_middleware: 164 164 response = middleware_method(request, response) 165 response = self.fix_up_response(request, response) 165 166 finally: 166 167 dispatcher.send(signal=signals.request_finished) 167 168 -
django/core/handlers/wsgi.py
207 207 # Apply response middleware 208 208 for middleware_method in self._response_middleware: 209 209 response = middleware_method(request, response) 210 response = self.fix_up_response(request, response) 210 211 finally: 211 212 dispatcher.send(signal=signals.request_finished) 212 213 -
django/middleware/http.py
6 6 Last-Modified header, and the request has If-None-Match or 7 7 If-Modified-Since, the response is replaced by an HttpNotModified. 8 8 9 Removes the content from any response to a HEAD request.10 11 9 Also sets the Date and Content-Length response-headers. 12 10 """ 13 11 def process_response(self, request, response): … … 19 17 if_none_match = request.META.get('HTTP_IF_NONE_MATCH', None) 20 18 if if_none_match == response['ETag']: 21 19 response.status_code = 304 22 response.content = ''23 response['Content-Length'] = '0'24 20 25 21 if response.has_header('Last-Modified'): 26 22 if_modified_since = request.META.get('HTTP_IF_MODIFIED_SINCE', None) 27 23 if if_modified_since == response['Last-Modified']: 28 24 response.status_code = 304 29 response.content = ''30 response['Content-Length'] = '0'31 25 32 if request.method == 'HEAD':33 response.content = ''34 35 26 return response 36 27 37 28 class SetRemoteAddrFromForwardedFor(object):