emptygif
Idioma: Português

Todas as linguagens e frameworks

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Um snippet em Python para Raw WSGI (Gunicorn, uWSGI, mod_wsgi) que responde às requisições para /pixel.gif com o GIF vazio, decodificado uma única vez na inicialização.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

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

Executamos este snippet e comparamos os bytes que ele retornou.

Verificar

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

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

Mais em Python