Skip to content

Commit

Permalink
Fetch user IP with 'X-Forward-For' (#13575)
Browse files Browse the repository at this point in the history
* Fetch user IP with 'X-Forward-For'

* Run format-python
  • Loading branch information
petesfrench authored Feb 13, 2024
1 parent a9058fa commit 9c0a086
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,13 @@ def thank_you():


def get_user_country_by_ip():
client_ip = flask.request.headers.get(
"X-Real-IP", flask.request.remote_addr
)
x_forwarded_for = flask.request.headers.get("X-Forwarded-For")

if x_forwarded_for:
client_ip = x_forwarded_for.split(",")[0]
else:
client_ip = flask.request.remote_addr

ip_location = ip_reader.get(client_ip)

try:
Expand Down

0 comments on commit 9c0a086

Please sign in to comment.