emptygif
Idioma: Español

Todos los lenguajes y frameworks

aiohttp Python

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

aiohttp Python

Instalar
pip install aiohttp
Archivo
server.py
Ejecutar
python server.py
import base64

from aiohttp import web

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

routes = web.RouteTableDef()


@routes.get("/pixel.gif")
async def pixel(request: web.Request) -> web.Response:
    return web.Response(
        body=GIF, content_type="image/gif", headers={"Cache-Control": "no-store"}
    )


app = web.Application()
app.add_routes(routes)

if __name__ == "__main__":
    web.run_app(app, port=8080)

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: aiohttp

Más en Python