Spaces:
Sleeping
Sleeping
direct CDN fetch: skip router for shabakaty CDN assets
Browse files3 unmodified lines4567891027 unmodified lines3839404142431 unmodified line4546474849503 unmodified linesimport sysimport uuidimport urllib.parsefrom aiohttp import webPORT = int(os.environ.get("PORT", 7860))27 unmodified linesexcept (UnicodeDecodeError, ValueError):return "application/octet-stream"async def proxy_handler(request):target_url = request.query.get("url")if not target_url:1 unmodified lineif not target_url.startswith(("http://", "https://")):target_url = "https://" + target_url.lstrip("/")rid = str(uuid.uuid4())event = asyncio.Event()result = {"body": b"", "status": 502, "content_type": "text/plain"}3 unmodified lines4567891027 unmodified lines38394041424344454647481 unmodified line505152535455565758596061626364656667686970713 unmodified linesimport sysimport uuidimport urllib.parsefrom aiohttp import web, ClientSession, ClientTimeoutPORT = int(os.environ.get("PORT", 7860))27 unmodified linesexcept (UnicodeDecodeError, ValueError):return "application/octet-stream"import aiohttpDIRECT_PREFIXES = ("https://cnth2.shabakaty.com/", "https://img.shabakaty.com/","https://cdn.shabakaty.com/", "https://static.shabakaty.com/")async def proxy_handler(request):target_url = request.query.get("url")if not target_url:1 unmodified lineif not target_url.startswith(("http://", "https://")):target_url = "https://" + target_url.lstrip("/")# Fetch CDN assets directly (fast, no router needed)if target_url.startswith(DIRECT_PREFIXES):try:async with ClientSession() as sess:async with sess.get(target_url, timeout=ClientTimeout(total=20)) as resp:body = await resp.read()ct = resp.content_type or "application/octet-stream"if ct in ("text/html", "text/plain", "application/octet-stream"):detected = detect_content_type(body, ct)if detected != ct:ct = detectedreturn web.Response(body=body, status=resp.status, content_type=ct)except Exception as e:return web.Response(body=str(e).encode(), status=502, content_type="text/plain")# Tunnel via router for geo-restricted URLsrid = str(uuid.uuid4())event = asyncio.Event()result = {"body": b"", "status": 502, "content_type": "text/plain"}
app.py+22-1