Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python
適用於 Raw WSGI (Gunicorn, uWSGI, mod_wsgi) 的 Python 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。
Raw WSGI (Gunicorn, uWSGI, mod_wsgi) Python
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)