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)