Skip to content

Commit

Permalink
[DEV-9027] change x-forwarded-for header ordering (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreznikoff authored Nov 29, 2022
1 parent dfa9d7a commit ef901b6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
python-tortik (0.2.10) unstable; urgency=low

* сhanged x-forwarded-for headers ordering

-- Vitaly Glibin <glibin.v@gmail.com> Fri, 29 Nov 2022 09:00:00 +0300

python-tortik (0.2.9) unstable; urgency=low

* remove redundant logs
Expand Down
2 changes: 1 addition & 1 deletion tortik/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def make_list(val):

def real_ip(request):
# split is for X-Forwarded-For header that can consist of many IPs: X-Forwarded-For: client, proxy1, proxy2
return (request.headers.get('X-Real-Ip', None) or request.headers.get('X-Forwarded-For', None) or
return (request.headers.get('X-Forwarded-For', None) or request.headers.get('X-Real-Ip', None) or
request.remote_ip or '127.0.0.1').split(',')[0]


Expand Down
2 changes: 1 addition & 1 deletion tortik/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ def __parse_version_from_changelog():
except (IOError, AttributeError):
return None

version = __parse_version_from_changelog() or '0.2.9'
version = __parse_version_from_changelog() or '0.2.10'
7 changes: 6 additions & 1 deletion tortik_tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ def test_real_ip(self):
request = Request()
request.headers = {'X-Real-Ip': '8.8.8.8', 'X-Forwarded-For': '10.0.0.1'}

self.assertEqual('8.8.8.8', real_ip(request))
self.assertEqual('10.0.0.1', real_ip(request))

request = Request()
request.headers = {'X-Forwarded-For': '10.0.0.1, 127.0.0.1'}

self.assertEqual('10.0.0.1', real_ip(request))

request = Request()
request.headers = {'X-Real-Ip': '8.8.8.8'}

self.assertEqual('8.8.8.8', real_ip(request))

0 comments on commit ef901b6

Please sign in to comment.