emptygif
Langue: Français

Tous les langages et frameworks

Litestar Python

Un extrait Python pour Litestar qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Litestar Python

Installer
pip install "litestar[standard]"
Fichier
app.py
Lancer
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])

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

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

Site officiel: Litestar

Autres extraits en Python