emptygif
زبان: اردو

تمام زبانیں اور فریم ورکس

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python

Raw WSGI (Gunicorn, uWSGI, mod_wsgi) کے لیے Python کا اسنیپٹ جو /pixel.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 میں مزید