emptygif
Language: English

All languages and frameworks

aiohttp Python

A Python snippet for aiohttp that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

aiohttp Python

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

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: aiohttp

More in Python