emptygif
Idioma: Español

Todos los lenguajes y frameworks

Litestar Python

Un fragmento en Python para Litestar que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

Litestar Python

Instalar
pip install "litestar[standard]"
Archivo
app.py
Ejecutar
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])

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Litestar

Más en Python