added logger

This commit is contained in:
Mathieu Broillet 2025-08-25 18:58:31 +02:00
parent 23accbfe1e
commit 1b77cf30cc
Signed by: mathieub
GPG Key ID: 4428608CDA3A98D3
3 changed files with 9 additions and 4 deletions

View File

@ -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"

View File

@ -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"}

View File

@ -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()