emptygif
Basa: Basa Jawa

Kabeh basa lan framework

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Snippet Python kanggo Raw WSGI (Gunicorn, uWSGI, mod_wsgi) sing mangsuli request menyang /pixel.gif nganggo empty GIF, sing didekode sepisan nalika startup.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Instal
pip install gunicorn
File
app.py
Lakokake
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"]

Snippet iki wis dilakokake lan byte asile wis dibandhingake.

Priksa

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

Situs resmi: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)

Liyane ing Python