Microdot (CPython and MicroPython) Python
一个用于 Microdot (CPython and MicroPython) 的 Python 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Microdot (CPython and MicroPython) Python
import binascii # available on MicroPython as well as CPython
from microdot import Microdot
GIF = binascii.a2b_base64("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
app = Microdot()
@app.get("/pixel.gif")
async def pixel(request):
return GIF, 200, {"Content-Type": "image/gif", "Cache-Control": "no-store"}
app.run(port=8080)
我们运行了此代码片段,并比对了它返回的字节。
验证
curl -sI http://localhost:8080/pixel.gif
官方网站: Microdot (CPython and MicroPython)