| | 1 | class 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 | |