emptygif
Language: English

All languages and frameworks

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

A Python snippet for Raw WSGI (Gunicorn, uWSGI, mod_wsgi) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Install
pip install gunicorn
File
app.py
Run
gunicorn --bind :8080 app:app
import base64

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
HEADERS = [
    ("Content-Type", "image/gif"),
    ("Content-Length", str(len(GIF))),
    ("Cache-Control", "no-store"),
]


def app(environ, start_response):
    if environ["REQUEST_METHOD"] == "GET" and environ["PATH_INFO"] == "/pixel.gif":
        start_response("200 OK", HEADERS)
        return [GIF]
    start_response("404 Not Found", [("Content-Type", "text/plain")])
    return [b"Not Found"]

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)

More in Python