Ticket #987: redirect_absoluteuri.patch
File redirect_absoluteuri.patch, 2.0 KB (added by , 17 years ago) |
---|
-
django/middleware/common.py
1 1 from django.conf import settings 2 2 from django import http 3 3 from django.core.mail import mail_managers 4 from urlparse import urljoin 4 5 import md5 5 6 import re 6 7 … … 17 18 - ETags: If the USE_ETAGS setting is set, ETags will be calculated from 18 19 the entire page content and Not Modified responses will be returned 19 20 appropriately. 21 22 - Absolute URI redirects: Ensures that any redirect attempt (which uses 23 the HTTP Location header) to a relative location is converted to an 24 absolute URI, as required by RFC 2616, section 14.30. 20 25 """ 21 26 22 27 def process_request(self, request): … … 84 89 else: 85 90 response['ETag'] = etag 86 91 92 # Absolute URI redirects. 93 if 'Location' in response.headers: 94 location = response['Location'] 95 if not ':' in location: 96 current_uri = '%s://%s%s' % (request.is_secure() and 'https' or 'http', 97 http.get_host(request), 98 request.path) 99 response['Location'] = urljoin(current_uri, location) 100 87 101 return response 88 102 89 103 def _is_ignorable_404(uri): -
docs/middleware.txt
78 78 MD5-hashing the page content, and it'll take care of sending 79 79 ``Not Modified`` responses, if appropriate. 80 80 81 * Ensures that any redirect attempt to a relative location is converted to an 82 absolute URI, as required by `RFC 2616`_. 83 84 .. _RFC 2616: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 85 81 86 django.middleware.doc.XViewMiddleware 82 87 ------------------------------------- 83 88