emptygif
语言: 简体中文

所有语言和框架

Pyramid Python

一个用于 Pyramid 的 Python 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。

Pyramid Python

安装
pip install pyramid
文件
app.py
运行
python app.py
import base64
from wsgiref.simple_server import make_server

from pyramid.config import Configurator
from pyramid.response import Response

GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")


def pixel(request):
    return Response(body=GIF, content_type="image/gif", cache_control="no-store")


if __name__ == "__main__":
    with Configurator() as config:
        config.add_route("pixel", "/pixel.gif")
        config.add_view(pixel, route_name="pixel", request_method="GET")
        app = config.make_wsgi_app()
    make_server("0.0.0.0", 8080, app).serve_forever()

我们运行了此代码片段,并比对了它返回的字节。

验证

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

官方网站: Pyramid

更多 Python 示例