Skip to content

Commit

Permalink
Fix MultipleProxyMiddleware
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 2, 2018
1 parent b5e00e0 commit f438256
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions daiquiri/core/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class MultipleProxyMiddleware(MiddlewareMixin):
"""
see also: https://docs.djangoproject.com/en/2.1/ref/request-response/
(but using the left most entry)
"""

FORWARDED_FOR_FIELDS = [
Expand All @@ -14,11 +15,8 @@ class MultipleProxyMiddleware(MiddlewareMixin):

def process_request(self, request):
"""
Rewrites the proxy headers so that only the most
recent proxy is used.
Rewrites the proxy headers so that only the most recent proxy is used.
"""
for field in self.FORWARDED_FOR_FIELDS:
if field in request.META:
if ',' in request.META[field]:
parts = request.META[field].split(',')
request.META[field] = parts[-1].strip()
request.META[field] = request.META[field].split(',')[0].strip()

0 comments on commit f438256

Please sign in to comment.