emptygif
Idioma: Español

Todos los lenguajes y frameworks

Sanic Python

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

Sanic Python

Instalar
pip install sanic
Archivo
server.py
Ejecutar
sanic server:app --port 8080
import base64

from sanic import Sanic
from sanic.response import raw

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

app = Sanic("pixel")


@app.get("/pixel.gif")
async def pixel(request):
    return raw(GIF, content_type="image/gif", headers={"Cache-Control": "no-store"})

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Sanic

Más en Python