From 6a205122e9c76630b9a0775295d90770f307740b Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 30 Jun 2022 10:10:46 +0500 Subject: log real client IP address --- server.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server.py b/server.py index c0b8fc5..e4ecaef 100755 --- a/server.py +++ b/server.py @@ -76,6 +76,13 @@ def setup_signal_handlers(httpd): class RequestHandler(http.server.SimpleHTTPRequestHandler): VOID = 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