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)