emptygif
Dil: Türkçe

Tüm diller ve framework'ler

Raw ASGI (Uvicorn, Granian, Hypercorn) Python

Raw ASGI (Uvicorn, Granian, Hypercorn) için, /pixel.gif isteklerine başlangıçta bir kez çözülen boş GIF ile yanıt veren bir Python örneği.

Raw ASGI (Uvicorn, Granian, Hypercorn) Python

Kurulum
pip install uvicorn
Dosya
app.py
Çalıştır
uvicorn app:app --port 8080
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""})

Bu örneği çalıştırıp döndürdüğü baytları karşılaştırdık.

Kontrol et

curl -sI http://localhost:8080/pixel.gif

Resmî site: Raw ASGI (Uvicorn, Granian, Hypercorn)

Python için daha fazlası