emptygif
Lingua: Italiano

Tutti i linguaggi e framework

aiohttp Python

Uno snippet Python per aiohttp che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

aiohttp Python

Installa
pip install aiohttp
File
server.py
Esegui
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)

Abbiamo eseguito questo snippet e confrontato i byte che ha restituito.

Verifica

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

Sito ufficiale: aiohttp

Altro in Python