added logger
This commit is contained in:
parent
23accbfe1e
commit
1b77cf30cc
3
const.py
3
const.py
@ -1,7 +1,10 @@
|
|||||||
|
import logging
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from datetime import datetime, timezone, timedelta
|
from datetime import datetime, timezone, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
logger = logging.getLogger("uvicorn")
|
||||||
|
|
||||||
|
|
||||||
class Hosts(str, Enum):
|
class Hosts(str, Enum):
|
||||||
PLEX = "plex.tv"
|
PLEX = "plex.tv"
|
||||||
|
@ -138,7 +138,8 @@ async def fake_user_json_or_signin(request: Request, _=host_required([Hosts.CLIE
|
|||||||
"plan": "monthly",
|
"plan": "monthly",
|
||||||
"paymentNotificationId": "1234567",
|
"paymentNotificationId": "1234567",
|
||||||
"canUpgrade": True,
|
"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": [
|
"subscriptions": [
|
||||||
{
|
{
|
||||||
@ -209,6 +210,7 @@ async def fake_claim_exchange(request: Request, _=host_required([Hosts.PLEX])):
|
|||||||
async def favicon():
|
async def favicon():
|
||||||
return FileResponse("favicon.ico")
|
return FileResponse("favicon.ico")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/proxy")
|
@app.get("/proxy")
|
||||||
async def hack():
|
async def hack():
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
6
utils.py
6
utils.py
@ -3,7 +3,7 @@ from fastapi import Request, Depends, HTTPException
|
|||||||
from fastapi.responses import Response
|
from fastapi.responses import Response
|
||||||
from starlette.responses import JSONResponse
|
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
|
from http_client_static_dns import AsyncCustomHost, NameSolver
|
||||||
|
|
||||||
# Configure upstream client
|
# Configure upstream client
|
||||||
@ -19,6 +19,7 @@ def host_required(allowed_hosts: list[Hosts]):
|
|||||||
async def dependency(request: Request):
|
async def dependency(request: Request):
|
||||||
host = request.url.hostname
|
host = request.url.hostname
|
||||||
if host not in [h.value for h in allowed_hosts]:
|
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")
|
raise HTTPException(status_code=403, detail=f"Host '{host}' not allowed")
|
||||||
|
|
||||||
return Depends(dependency)
|
return Depends(dependency)
|
||||||
@ -26,8 +27,7 @@ def host_required(allowed_hosts: list[Hosts]):
|
|||||||
|
|
||||||
async def call_official(request: Request, path: str) -> httpx.Response:
|
async def call_official(request: Request, path: str) -> httpx.Response:
|
||||||
"""Forward the incoming request to the official API and return the 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
|
# Copy request body
|
||||||
body = await request.body()
|
body = await request.body()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user