Raw ASGI (Uvicorn, Granian, Hypercorn) Python
/pixel.gif కు వచ్చే రిక్వెస్ట్లకు empty GIF తో జవాబిచ్చే, Raw ASGI (Uvicorn, Granian, Hypercorn) కోసం Python స్నిపెట్. 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)