From 22a10c01180902eb2d5587aedd80d6c64eef32db Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 30 Jun 2022 12:36:35 +0500 Subject: log real client IP address --- src/server.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/server.py b/src/server.py index a0fa7c4..64b6d47 100755 --- a/src/server.py +++ b/src/server.py @@ -32,6 +32,13 @@ def default_html_dir(): class RequestHandler(http.server.SimpleHTTPRequestHandler): ARGS = None + def address_string(self): + if 'x-forwarded-for' in self.headers: + return self.headers['x-forwarded-for'].split(',')[0].strip() + if 'x-real-ip' in self.headers: + return self.headers['x-real-ip'] + return super().address_string() + def do_GET(self): try: request = Request.from_http_path(self.path) -- cgit v1.2.3