Ticket #4148: 5079-fix_ie_cache_bugs.diff

File 5079-fix_ie_cache_bugs.diff, 2.4 KB (added by Michael Axiak <axiak@…>, 17 years ago)

Cleaned the patch a little bit...added fix for content-disposition

  • django/core/handlers/base.py

     
    33from django import http
    44import sys
    55
     6def fix_IE_for_attach(request, response):
     7    """
     8    This function will prevent Django from serving a
     9    Content-Disposition header while expecting the browser
     10    to cache it. This leads to IE not allowing the client
     11    to download.
     12    """
     13    try:
     14        if 'MSIE' not in request.META['User-Agent'].upper():
     15            return response
     16    except KeyError:
     17        return response
     18
     19    if response.has_header('Content-Disposition'):
     20        del response['Pragma']
     21        response['Cache-Control'] = 'must-revalidate, post-check=0, pre-check=0'
     22       
     23    return response
     24
     25def fix_IE_for_vary(request, response):
     26    """
     27    This function will fix the bug reported at
     28    http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global
     29    by clearing the Vary header whenever the mime-type is not safe
     30    enough for Internet Explorer to handle.
     31    """
     32   
     33    # a list of mime-types that are decreed "Vary-safe" for IE
     34    safe_mime_types = ('text/html',
     35                       'text/plain',
     36                       'text/sgml',
     37                       )
     38
     39    # establish that the user is using IE
     40    try:
     41        if 'MSIE' not in request.META['User-Agent'].upper():
     42            return response
     43    except KeyError:
     44        return response
     45
     46
     47    # IE will break
     48    if response.mimetype.lower() not in safe_mime_types:
     49        try:
     50            del response['Vary']
     51            response['Pragma'] = 'no-cache'
     52            response['Cache-Control'] = 'no-cache, must-revalidate'
     53        except KeyError:
     54            return response
     55           
     56    return response
     57
    658class BaseHandler(object):
    759    def __init__(self):
    860        self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None
     
    1769        from django.core import exceptions
    1870        self._request_middleware = []
    1971        self._view_middleware = []
    20         self._response_middleware = []
     72        # add processing for IE caching bugs
     73        self._response_middleware = [fix_IE_for_vary,fix_IE_for_attach]
     74           
    2175        self._exception_middleware = []
    2276        for middleware_path in settings.MIDDLEWARE_CLASSES:
    2377            try:
Back to Top