INNER CODE UNIT · Python

_host_without_port

arvin341az-glitch/RVG · main.py:106

def _host_without_port(raw_host: str) -> str:
    h = raw_host.strip()
    if not h:
        return ""
    if h.startswith("["):  # IPv6 literal, e.g. [::1]:8000
        return h.split("]")[0].lstrip("[")
    if h.count(":") == 1:  # host:port
        return h.split(":", 1)[0]
    return h


@app.middleware("http")
async def _detect_public_host(request: Request, call_next):
    # X-Forwarded-Host رو اول چک می‌کنیم چون پشت پروکسی‌هایی مثل Cloudflare یا
    # هر ری‌ورس‌پروکسی دیگه (مثلاً روی lucity.cloud)، هدر Host ممکنه داخلی
    # باشه ولی X-Forwarded-Host دامنه‌ی واقعی‌ای هست که کاربر توی مرورگرش می‌بینه.
    raw_host = (
        request.headers.get("x-forwarded-host", "").split(",")[0].strip()

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…