diff --git a/const.py b/const.py index ed09b39..a115787 100644 --- a/const.py +++ b/const.py @@ -1,7 +1,10 @@ +import logging import xml.etree.ElementTree as ET from datetime import datetime, timezone, timedelta from enum import Enum +logger = logging.getLogger("uvicorn") + class Hosts(str, Enum): PLEX = "plex.tv" diff --git a/main_app.py b/main_app.py index 8645d54..02dc9ba 100644 --- a/main_app.py +++ b/main_app.py @@ -138,7 +138,8 @@ async def fake_user_json_or_signin(request: Request, _=host_required([Hosts.CLIE "plan": "monthly", "paymentNotificationId": "1234567", "canUpgrade": True, - "features": PLEXAMP_FEATURES if "plexamp" in request.headers.get("X-Plex-Product", "").lower() else FEATURES_DICT + "features": PLEXAMP_FEATURES if "plexamp" in request.headers.get("X-Plex-Product", + "").lower() else FEATURES_DICT }, "subscriptions": [ { @@ -209,6 +210,7 @@ async def fake_claim_exchange(request: Request, _=host_required([Hosts.PLEX])): async def favicon(): return FileResponse("favicon.ico") + @app.get("/proxy") async def hack(): return {"status": "ok"} diff --git a/utils.py b/utils.py index 1f31d12..afc43ad 100644 --- a/utils.py +++ b/utils.py @@ -3,7 +3,7 @@ from fastapi import Request, Depends, HTTPException from fastapi.responses import Response from starlette.responses import JSONResponse -from const import Hosts, HOP_BY_HOP_HEADERS +from const import Hosts, HOP_BY_HOP_HEADERS, logger from http_client_static_dns import AsyncCustomHost, NameSolver # Configure upstream client @@ -19,6 +19,7 @@ def host_required(allowed_hosts: list[Hosts]): async def dependency(request: Request): host = request.url.hostname if host not in [h.value for h in allowed_hosts]: + logger.warning(f"Host '{host}' not allowed for url '{request.url}'") raise HTTPException(status_code=403, detail=f"Host '{host}' not allowed") return Depends(dependency) @@ -26,8 +27,7 @@ def host_required(allowed_hosts: list[Hosts]): async def call_official(request: Request, path: str) -> httpx.Response: """Forward the incoming request to the official API and return the response.""" - print(f"Processing request to {str(request.url)}") - + logger.debug(f"Forwarding request to official: {request.method} {request.url}") # Copy request body body = await request.body()