emptygif
Wika: Filipino

Lahat ng language at framework

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Isang Python snippet para sa Raw WSGI (Gunicorn, uWSGI, mod_wsgi) na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

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

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)

Iba pa sa Python