emptygif
भाषा: मराठी

सर्व भाषा आणि फ्रेमवर्क

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) साठी Python स्निपेट, जो /pixel.gif वरच्या रिक्वेस्टना empty GIF ने उत्तर देतो. GIF स्टार्टअपला एकदाच डिकोड होतो.

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

इन्स्टॉल
pip install gunicorn
फाइल
app.py
चालवा
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"]

आम्ही हा स्निपेट चालवला आणि त्याने परत केलेले बाइट्स तुलना करून पाहिले.

तपासा

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

अधिकृत साइट: Raw WSGI (Gunicorn, uWSGI, mod_wsgi)

Python मध्ये आणखी