emptygif
Language: English

All languages and frameworks

Falcon Python

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

Falcon Python

Install
pip install falcon uvicorn
File
app.py
Run
uvicorn app:app --port 8080
import base64

import falcon.asgi

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


class PixelResource:
    async def on_get(self, req: falcon.asgi.Request, resp: falcon.asgi.Response) -> None:
        resp.content_type = "image/gif"
        resp.cache_control = ["no-store"]
        resp.data = GIF


app = falcon.asgi.App()
app.add_route("/pixel.gif", PixelResource())

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Falcon

More in Python