app = FastAPI( title="Heroku Web‑DL", description="A tiny HTTP API that streams any publicly reachable file back to the caller.", version="0.1.0", )
workers = int(os.getenv("WEB_CONCURRENCY", cpu_count() * 2 + 1)) max_requests = 1000 # graceful restart after N requests max_requests_jitter = 50 timeout = 30 # Heroku’s request timeout (30 s on free/standard) loglevel = "info" 4.1 app/config.py # app/config.py import os from pathlib import Path from dotenv import load_dotenv heretic webdl
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. app = FastAPI( title="Heroku Web‑DL"
# 2️⃣ Create a virtualenv python3 -m venv venv source venv/bin/activate ) workers = int(os.getenv("WEB_CONCURRENCY"
# 5️⃣ Run the dev server uvicorn app.main:app --reload Open http://127.0.0.1:8000/docs – you’ll see the interactive Swagger UI. # Dockerfile FROM python:3.11-slim
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
import httpx from fastapi import HTTPException, status from .config import settings