emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Litestar Python

Ein Python-Snippet für Litestar, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Litestar Python

Installieren
pip install "litestar[standard]"
Datei
app.py
Ausführen
litestar --app app:app run --port 8080
import base64

from litestar import Litestar, get
from litestar.datastructures import CacheControlHeader

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")


@get(
    "/pixel.gif",
    media_type="image/gif",
    cache_control=CacheControlHeader(no_store=True),
    include_in_schema=False,
)
async def pixel() -> bytes:
    return GIF


app = Litestar([pixel])

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Litestar

Mehr in Python