Heretic Webdl [Deluxe — 2026]

return StreamingResponse( generator(), media_type=headers.get("Content-Type", "application/octet-stream"), headers=headers, )

if parsed.scheme not in "http", "https": raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail="Only http and https URLs are supported.", ) heretic webdl

class Settings: # ---- security / abuse limits ------------------------------------------------- MAX_CONTENT_LENGTH = int(os.getenv("MAX_CONTENT_LENGTH", "104857600")) # 100 MiB # Optional whitelist (comma‑separated). If empty → allow any domain. WHITELISTED_DOMAINS = set( filter(None, os.getenv("WHITELISTED_DOMAINS", "").split(",")) ) # Rate limiting – simple token bucket stored in memory (good enough for free tier) RATE_LIMIT = int(os.getenv("RATE_LIMIT", "10")) # requests per minute per IP return StreamingResponse( generator(), media_type=headers

headers = "Content-Disposition": f'attachment; filename="filename"', # The downstream `StreamingResponse` will automatically forward # the `Content-Type` from the remote response if we set it later. except httpx

except httpx.RequestError as exc: raise HTTPException( status_code=status.HTTP_504_GATEWAY_TIMEOUT, detail=f"Error contacting remote host: exc", ) # app/main.py import time from collections import defaultdict from datetime import datetime, timedelta from typing import Dict

def _check_rate_limit(ip: str) -> None: now = datetime.utcnow() window_start = now - timedelta(minutes=1)

# Load .env only when running locally (Heroku injects env vars itself) if Path(".env").exists(): load_dotenv(".env")