Falcon Python
一个用于 Falcon 的 Python 代码片段,以空 GIF 响应对 /pixel.gif 的请求,GIF 在启动时只解码一次。
Falcon Python
import base64
import falcon.asgi
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
class PixelResource:
async def on_get(self, req: falcon.asgi.Request, resp: falcon.asgi.Response) -> None:
resp.content_type = "image/gif"
resp.cache_control = ["no-store"]
resp.data = GIF
app = falcon.asgi.App()
app.add_route("/pixel.gif", PixelResource())
我们运行了此代码片段,并比对了它返回的字节。
验证
curl -sI http://localhost:8080/pixel.gif
更多 Python 示例
- AWS Lambda (Python)
- Google Cloud Run functions (Python)
- FastAPI
- Litestar
- Starlette
- Django
- Flask
- aiohttp
- Sanic
- Quart
- Robyn
- BlackSheep
- Tornado
- Bottle
- Pyramid
- Microdot (CPython and MicroPython)
- Raw ASGI (Uvicorn, Granian, Hypercorn)
- Raw WSGI (Gunicorn, uWSGI, mod_wsgi)
- Python standard library (http.server)
- Python one-liner