Starlette Python
Đoạn mã Python cho Starlette, trả lời các yêu cầu tới /pixel.gif bằng GIF rỗng, được giải mã một lần khi khởi động.
Starlette Python
import base64
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route
GIF = base64.b64decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
async def pixel(request: Request) -> Response:
return Response(GIF, media_type="image/gif", headers={"Cache-Control": "no-store"})
app = Starlette(routes=[Route("/pixel.gif", pixel)])
Chúng tôi đã chạy đoạn mã này và so sánh các byte nó trả về.
Kiểm tra
curl -sI http://localhost:8080/pixel.gif