+0
-100
lines changedFilter options
+0
-100
lines changed Original file line number Diff line number Diff line change
@@ -14,8 +14,6 @@ class BaseHandler(object):
14
14
response_fixes = [
15
15
http.fix_location_header,
16
16
http.conditional_content_removal,
17
-
http.fix_IE_for_attach,
18
-
http.fix_IE_for_vary,
19
17
]
20
18
21
19
def __init__(self):
Original file line number Diff line number Diff line change
@@ -31,57 +31,3 @@ def conditional_content_removal(request, response):
31
31
if request.method == 'HEAD':
32
32
response.content = ''
33
33
return response
34
-
35
-
def fix_IE_for_attach(request, response):
36
-
"""
37
-
This function will prevent Django from serving a Content-Disposition header
38
-
while expecting the browser to cache it (only when the browser is IE). This
39
-
leads to IE not allowing the client to download.
40
-
"""
41
-
useragent = request.META.get('HTTP_USER_AGENT', '').upper()
42
-
if 'MSIE' not in useragent and 'CHROMEFRAME' not in useragent:
43
-
return response
44
-
45
-
offending_headers = ('no-cache', 'no-store')
46
-
if response.has_header('Content-Disposition'):
47
-
try:
48
-
del response['Pragma']
49
-
except KeyError:
50
-
pass
51
-
if response.has_header('Cache-Control'):
52
-
cache_control_values = [value.strip() for value in
53
-
response['Cache-Control'].split(',')
54
-
if value.strip().lower() not in offending_headers]
55
-
56
-
if not len(cache_control_values):
57
-
del response['Cache-Control']
58
-
else:
59
-
response['Cache-Control'] = ', '.join(cache_control_values)
60
-
61
-
return response
62
-
63
-
def fix_IE_for_vary(request, response):
64
-
"""
65
-
This function will fix the bug reported at
66
-
http://support.microsoft.com/kb/824847/en-us?spid=8722&sid=global
67
-
by clearing the Vary header whenever the mime-type is not safe
68
-
enough for Internet Explorer to handle. Poor thing.
69
-
"""
70
-
useragent = request.META.get('HTTP_USER_AGENT', '').upper()
71
-
if 'MSIE' not in useragent and 'CHROMEFRAME' not in useragent:
72
-
return response
73
-
74
-
# These mime-types that are decreed "Vary-safe" for IE:
75
-
safe_mime_types = ('text/html', 'text/plain', 'text/sgml')
76
-
77
-
# The first part of the Content-Type field will be the MIME type,
78
-
# everything after ';', such as character-set, can be ignored.
79
-
mime_type = response.get('Content-Type', '').partition(';')[0]
80
-
if mime_type not in safe_mime_types:
81
-
try:
82
-
del response['Vary']
83
-
except KeyError:
84
-
pass
85
-
86
-
return response
87
-
Original file line number Diff line number Diff line change
@@ -56,50 +56,6 @@ def test_urlencode(self):
56
56
]
57
57
self.assertTrue(result in acceptable_results)
58
58
59
-
def test_fix_IE_for_vary(self):
60
-
"""
61
-
Regression for #16632.
62
-
63
-
`fix_IE_for_vary` shouldn't crash when there's no Content-Type header.
64
-
"""
65
-
66
-
# functions to generate responses
67
-
def response_with_unsafe_content_type():
68
-
r = HttpResponse(content_type="text/unsafe")
69
-
r['Vary'] = 'Cookie'
70
-
return r
71
-
72
-
def no_content_response_with_unsafe_content_type():
73
-
# 'Content-Type' always defaulted, so delete it
74
-
r = response_with_unsafe_content_type()
75
-
del r['Content-Type']
76
-
return r
77
-
78
-
# request with & without IE user agent
79
-
rf = RequestFactory()
80
-
request = rf.get('/')
81
-
ie_request = rf.get('/', HTTP_USER_AGENT='MSIE')
82
-
83
-
# not IE, unsafe_content_type
84
-
response = response_with_unsafe_content_type()
85
-
utils.fix_IE_for_vary(request, response)
86
-
self.assertTrue('Vary' in response)
87
-
88
-
# IE, unsafe_content_type
89
-
response = response_with_unsafe_content_type()
90
-
utils.fix_IE_for_vary(ie_request, response)
91
-
self.assertFalse('Vary' in response)
92
-
93
-
# not IE, no_content
94
-
response = no_content_response_with_unsafe_content_type()
95
-
utils.fix_IE_for_vary(request, response)
96
-
self.assertTrue('Vary' in response)
97
-
98
-
# IE, no_content
99
-
response = no_content_response_with_unsafe_content_type()
100
-
utils.fix_IE_for_vary(ie_request, response)
101
-
self.assertFalse('Vary' in response)
102
-
103
59
def test_base36(self):
104
60
# reciprocity works
105
61
for n in [0, 1, 1000, 1000000, sys.maxint]:
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4