Ticket #4148: 5065-fix_ie_error_bug__for_4148.diff

File 5065-fix_ie_error_bug__for_4148.diff, 2.3 KB (added by Michael Axiak <axiak@…>, 17 years ago)

The middleware. It includes the documentation.

  • django/middleware/fixievarybug.py

     
     1class FixIEVaryBugMiddleware(object):
     2    """
     3    Quick MiddleWare that will fix the bug reported at
     4    http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global (thanks aconbere)
     5    for Internet Explorer since Microsoft doesn't know how to do HTTP.
     6
     7    To use: Make sure you put this at the *beginning* of your middleware
     8    list (since Django applies responses in reverse order).
     9    """
     10
     11    def process_response(self, request, response):
     12
     13        # a list of mime-types that are decreed "Vary-safe" for IE
     14        safe_mime_types = ('text/html',
     15                           'text/plain',
     16                           'text/sgml',
     17                           )
     18
     19        # establish that the user is using IE
     20        try:
     21            if 'MSIE' not in request.META['User-Agent'].upper():
     22                return response
     23        except KeyError:
     24            return response
     25
     26
     27        # IE will break
     28        if response.mimetype.lower() not in safe_mime_types:
     29            try:
     30                del response['Vary']
     31                response['Pragma'] = 'no-cache'
     32                response['Cache-Control'] = 'no-cache, must-revalidate'
     33            except KeyError:
     34                return response
     35
     36        return response
     37       
  • docs/middleware.txt

     
    116116``HTTP_X_FORWARDED_FOR``, that means anybody can "fake" their IP address. Only
    117117use this when you can absolutely trust the value of ``HTTP_X_FORWARDED_FOR``.
    118118
     119django.middleware.fixievarybug.FixIEVaryBugMiddleware
     120-----------------------------------------------------
     121
     122Fixes the Internet Explorer (IE) vary bug described at
     123http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global. If you are
     124generating PDF files and you expect IE to work with your site, just enable
     125this middleware.
     126
    119127django.contrib.sessions.middleware.SessionMiddleware
    120128----------------------------------------------------
    121129
Back to Top