Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Update icanhazip to return IP supporting X-Forwarded-For headers
Browse files Browse the repository at this point in the history
  • Loading branch information
gregswift committed Feb 7, 2018
1 parent c0ea0b6 commit 8b60ea8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion icanhaz.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def icanhazafunction():
result = json.dumps(dict(request.headers))
else:
# The request is for *.icanhazip.com or something we don't recognize
result = request.remote_addr
# This method should pull the correct hop even with load balancers in the way
# https://stackoverflow.com/questions/33818540/how-to-get-the-first-client-ip-from-x-forwarded-for-behind-nginx-gunicorn
result = request.access_route[0]
return Response("%s\n" % result, mimetype="text/plain", headers={'X-Your-Ip': request.remote_addr})


Expand Down

0 comments on commit 8b60ea8

Please sign in to comment.