emptygif
Langue: Français

Tous les langages et frameworks

Starlette Python

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

Starlette Python

Installer
pip install starlette uvicorn
Fichier
app.py
Lancer
uvicorn app:app --port 8080
import base64

from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route

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


async def pixel(request: Request) -> Response:
    return Response(GIF, media_type="image/gif", headers={"Cache-Control": "no-store"})


app = Starlette(routes=[Route("/pixel.gif", 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: Starlette

Autres extraits en Python