emptygif
Idioma: Português

Todas as linguagens e frameworks

aiohttp Python

Um snippet em Python para aiohttp que responde às requisições para /pixel.gif com o GIF vazio, decodificado uma única vez na inicialização.

aiohttp Python

Instalar
pip install aiohttp
Arquivo
server.py
Executar
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)

Executamos este snippet e comparamos os bytes que ele retornou.

Verificar

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

Site oficial: aiohttp

Mais em Python