Apparently Internet Explorer (6 and 7) have a bug whereby if you blindly attach a PDF or some other file, it will choke. The problem lies in the Vary header (bug described in http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global).
To use, just add to the beginning of your middleware classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
class FixIEVaryBugMiddleware(object): """ Quick MiddleWare that will fix the bug reported at http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global (thanks aconbere) for Internet Explorer since Microsoft doesn't know how to do HTTP. To use: Make sure you put this at the *beginning* of your middleware list (since Django applies responses in reverse order). """ def process_response(self, request, response): # a list of mime-types that are decreed "Vary-safe" for IE safe_mime_types = ('text/html', 'text/plain', 'text/sgml', ) # establish that the user is using IE try: if 'MSIE' not in request.META['User-Agent'].upper(): return response except KeyError: return response # IE will break if response.mimetype.lower() not in safe_mime_types: try: del response['Vary'] response['Pragma'] = 'no-cache' response['Cache-Control'] = 'no-cache, must-revalidate' except KeyError: return response return response
More like this
- Stuff by NixonDash 3 weeks, 6 days ago
- Add custom fields to the built-in Group model by jmoppel 3 months ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 6 months, 2 weeks ago
- Python Django CRUD Example Tutorial by tuts_station 6 months, 4 weeks ago
- Browser-native date input field by kytta 8 months, 1 week ago
FUD: Don't use this unless you know what you're doing.
The Vary header controls upstream caching, and removing it from a response is dangerous to do in the general case.
Consider a PDF containing private data, which you'd like to cache. You might Vary by cookie (which has session ID).
Deleting the Vary header in the response allows upstream caches to serve the prior response to the new requestor, even though the prior response should have been private to that requestor's session, per the Vary header.
As a reply to jdunck's FUD, I have modified the middleware to explicitly tell everyone to just NOT cache this file entirely.
(Better safe than sorry.)
Please login first before commenting.