emptygif
Idioma: Español

Todos los lenguajes y frameworks

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Un fragmento en Python para Raw WSGI (Gunicorn, uWSGI, mod_wsgi) que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Instalar
pip install gunicorn
Archivo
app.py
Ejecutar
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"]

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)

Más en Python