Ticket #4148: 5078-fix_ie_vary_bug_core__for_4148.diff
File 5078-fix_ie_vary_bug_core__for_4148.diff, 2.9 KB (added by , 18 years ago) |
---|
-
conf/global_settings.py
240 240 # isExistingURL validator. 241 241 URL_VALIDATOR_USER_AGENT = "Django/0.96pre (http://www.djangoproject.com)" 242 242 243 # A boolean that determines whether or not the response will have the Vary 244 # header removed to work with Internet Explorer in some cases. 245 ENABLE_IE_VARY_FIX = True 246 243 247 ############## 244 248 # MIDDLEWARE # 245 249 ############## -
core/handlers/base.py
3 3 from django import http 4 4 import sys 5 5 6 def fix_IE_for_vary(request, response): 7 """ 8 This function will fix the bug reported at 9 http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global 10 by clearing the Vary header whenever the mime-type is not safe 11 enough for Internet Explorer to handle. 12 """ 13 14 # a list of mime-types that are decreed "Vary-safe" for IE 15 safe_mime_types = ('text/html', 16 'text/plain', 17 'text/sgml', 18 ) 19 20 # establish that the user is using IE 21 try: 22 if 'MSIE' not in request.META['User-Agent'].upper(): 23 return response 24 except KeyError: 25 return response 26 27 28 # IE will break 29 if response.mimetype.lower() not in safe_mime_types: 30 try: 31 del response['Vary'] 32 response['Pragma'] = 'no-cache' 33 response['Cache-Control'] = 'no-cache, must-revalidate' 34 except KeyError: 35 return response 36 37 return response 38 6 39 class BaseHandler(object): 7 40 def __init__(self): 8 41 self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None … … 17 50 from django.core import exceptions 18 51 self._request_middleware = [] 19 52 self._view_middleware = [] 20 self._response_middleware = [] 53 if settings.ENABLE_IE_VARY_FIX: 54 self._response_middleware = [fix_IE_for_vary] 55 else: 56 self._response_middleware = [] 57 21 58 self._exception_middleware = [] 22 59 for middleware_path in settings.MIDDLEWARE_CLASSES: 23 60 try: … … 45 82 self._view_middleware.append(mw_instance.process_view) 46 83 if hasattr(mw_instance, 'process_response'): 47 84 self._response_middleware.insert(0, mw_instance.process_response) 85 48 86 if hasattr(mw_instance, 'process_exception'): 49 87 self._exception_middleware.insert(0, mw_instance.process_exception) 88 50 89 51 90 def get_response(self, request): 52 91 "Returns an HttpResponse object for the given HttpRequest"