Skip to content

Commit

Permalink
Merge pull request #2 from rhoog/master
Browse files Browse the repository at this point in the history
fallback naar HTTP_X_FORWARDED_FOR
  • Loading branch information
ivorbosloper committed May 27, 2016
2 parents 555144f + b4fa758 commit e3c813c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions user_sessions/middleware.py
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.utils.cache import patch_vary_headers
from django.utils.http import cookie_date
from django.utils.importlib import import_module
from importlib import import_module


class SessionMiddleware(object):
Expand All @@ -13,8 +13,10 @@ class SessionMiddleware(object):
def process_request(self, request):
engine = import_module(settings.SESSION_ENGINE)
session_key = request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
ip = request.META.get('REMOTE_ADDR') or request.META.get('HTTP_X_FORWARDED_FOR', '')
ip = ip.split(',')[0]
request.session = engine.SessionStore(
ip=request.META.get('REMOTE_ADDR', ''),
ip=ip,
user_agent=request.META.get('HTTP_USER_AGENT', ''),
session_key=session_key
)
Expand Down

0 comments on commit e3c813c

Please sign in to comment.