emptygif
Language: English

All languages and frameworks

Sanic Python

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

Sanic Python

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

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Sanic

More in Python