add get_ip_addr util function for servers behind proxies

This commit is contained in:
2023-03-12 01:00:51 -05:00
parent ea14f105d5
commit 18a95f5213
9 changed files with 33 additions and 20 deletions

View File

@ -1,5 +1,6 @@
from typing import Dict, Any
from types import ModuleType
from twisted.web.http import Request
import logging
import importlib
from os import walk
@ -21,3 +22,7 @@ class Utils:
logging.getLogger("core").error(f"get_all_titles: {dir} - {e}")
raise
return ret
@classmethod
def get_ip_addr(cls, req: Request) -> str:
return req.getAllHeaders()[b"x-forwarded-for"].decode() if b"x-forwarded-for" in req.getAllHeaders() else req.getClientAddress().host