Skip to content

Commit

Permalink
Merge ab0020f into 15f7af6
Browse files Browse the repository at this point in the history
  • Loading branch information
jaap3 committed Dec 2, 2019
2 parents 15f7af6 + ab0020f commit 3744449
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -4,7 +4,9 @@ Changelog for Django-Fiber
1.7 (unreleased)
----------------

- Nothing changed yet.
- Reset 'Content-Length' header in AdminPageMiddleware and
ObfuscateEmailAddressMiddleware to make sure clients read
the full response.


1.6.1 (2019-10-17)
Expand Down
8 changes: 8 additions & 0 deletions fiber/middleware.py
Expand Up @@ -131,6 +131,10 @@ def modify_response(self, request, response):
'fiber_data': escape(json.dumps(fiber_data, sort_keys=True))
}
response.content = self.body_re.sub(replacement, content)
if response.has_header('Content-Length'):
# Reset 'Content-Length' header (usually set by CommonMiddleware)
# to make sure clients read the full response body
response['Content-Length'] = str(len(response.content))
return response

def is_django_admin(self, request):
Expand Down Expand Up @@ -169,6 +173,10 @@ def process_response(self, request, response):
email_pattern = re.compile(
r'\b(?P<email>(mailto:)?[\w-]+(\.[\w-]+)*(\+[\w-]+)?@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]+)))\b')
response.content = email_pattern.sub(self.replace_email, force_text(response.content))
if response.has_header('Content-Length'):
# Reset 'Content-Length' header (usually set by CommonMiddleware)
# to make sure clients read the full response body
response['Content-Length'] = str(len(response.content))
return response

def replace_email(self, matches):
Expand Down

0 comments on commit 3744449

Please sign in to comment.