Browse files

Since Django 1.5, for some reason static files that are served when D…


is True, no longer have a Content-Type set when when the server tries to
return a `304 - Not Modified`, and thus may result in a
KeyError. This commit fixes that.
  • Loading branch information...
markotibold committed Feb 28, 2013
1 parent a3c7e1d commit 5d4fc8468a825581379e3df5a60bce2178ac4521
Showing with 16 additions and 3 deletions.
  1. +16 −3 fiber/
@@ -12,6 +12,16 @@
from .utils.import_util import import_element
def is_non_html(response):
Returns True if the response has no Content-type set or is not `text/html`
or not `application/xhtml+xml`.
content_type = response.get('Content-Type')
if content_type is None or content_type.split(';')[0] not in ('text/html', 'application/xhtml+xml'):
return True
class AdminPageMiddleware(object):
body_re = re.compile(
@@ -23,8 +33,10 @@ def __init__(self):
def process_response(self, request, response):
# only process html and xhtml responses
if response['Content-Type'].split(';')[0] not in ('text/html', 'application/xhtml+xml'):
if is_non_html(response):
return response
if self.set_login_session(request, response):
request.session['show_fiber_admin'] = True
url_without_fiber = request.path_info.replace(LOGIN_STRING, '')
@@ -178,8 +190,9 @@ class ObfuscateEmailAddressMiddleware(object):
def process_response(self, request, response):
email_pattern = re.compile(r'(mailto:)?[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))')
if response['Content-Type'].split(';')[0] in ('text/html', 'application/xhtml+xml'):
response.content = email_pattern.sub(self.encode_string_repl, response.content)
if is_non_html(response):
return response
response.content = email_pattern.sub(self.encode_string_repl, response.content)
return response
def encode_string_repl(self, email_pattern_match):

0 comments on commit 5d4fc84

Please sign in to comment.