Raw ASGI (Uvicorn, Granian, Hypercorn) Python
Raw ASGI (Uvicorn, Granian, Hypercorn) साठी Python स्निपेट, जो /pixel.gif वरच्या रिक्वेस्टना empty GIF ने उत्तर देतो. GIF स्टार्टअपला एकदाच डिकोड होतो.
Raw ASGI (Uvicorn, Granian, Hypercorn) Python
import base64
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
HEADERS = [
(b"content-type", b"image/gif"),
(b"content-length", str(len(GIF)).encode()),
(b"cache-control", b"no-store"),
]
async def app(scope, receive, send):
if scope["type"] != "http":
return
if scope["method"] == "GET" and scope["path"] == "/pixel.gif":
await send({"type": "http.response.start", "status": 200, "headers": HEADERS})
await send({"type": "http.response.body", "body": GIF})
else:
await send({"type": "http.response.start", "status": 404, "headers": []})
await send({"type": "http.response.body", "body": b""})
आम्ही हा स्निपेट चालवला आणि त्याने परत केलेले बाइट्स तुलना करून पाहिले.
तपासा
curl -sI http://localhost:8080/pixel.gif
अधिकृत साइट: Raw ASGI (Uvicorn, Granian, Hypercorn)