Skip to content

Commit

Permalink
Add ability to read forwarded-for header. (#46)
Browse files Browse the repository at this point in the history
This helps when the websockets are behind a proxyserver, like Cloudflare
  • Loading branch information
Chrezm authored Mar 22, 2022
1 parent 2747be1 commit 2ff5b7c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/network/aoprotocol_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ def get_extra_info(self, key):
:param key: requested key
"""
info = {"peername": self.ws.remote_address}
remote_address = self.ws.remote_address
if (remote_address[0] == "127.0.0.1"):
# See if proxy
try:
remote_address = (self.ws.request_headers['X-Forwarded-For'], 0)
except:
pass
info = {"peername": remote_address}
return info[key]

def write(self, message):
Expand Down

0 comments on commit 2ff5b7c

Please sign in to comment.