Heretic Webdl =link= -

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.

# Stream in 256 KB chunks (feel free to tune) bytes_sent = 0 async for chunk in resp.aiter_bytes(chunk_size=256 * 1024): bytes_sent += len(chunk) if bytes_sent > settings.MAX_CONTENT_LENGTH: raise HTTPException( status_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE, detail="Remote file exceeds the allowed size limit (while streaming).", ) yield chunk

# 2️⃣ Create a virtualenv python3 -m venv venv source venv/bin/activate heretic webdl

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

CMD ["gunicorn", "-k", "uvicorn

from .downloader import stream_remote_file from .config import settings

# --------------------------------------------------- # # Simple in‑memory rate limiter (IP → timestamps) # --------------------------------------------------- # _rate_limiter: Dict[str, list[datetime]] = defaultdict(list) headers = "Content-Disposition": f'attachment

# --------------------------------------------------- # # Main download endpoint # --------------------------------------------------- # @app.post("/download") async def download(req: Request, payload: DownloadRequest): client_ip = req.client.host _check_rate_limit(client_ip)