emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Ein Python-Snippet für Raw WSGI (Gunicorn, uWSGI, mod_wsgi), das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Installieren
pip install gunicorn
Datei
app.py
Ausführen
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"]

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)

Mehr in Python