emptygif
言語: 日本語

すべての言語・フレームワーク

Litestar Python

/pixel.gif へのリクエストに空の GIF を返す、Litestar 用の Python スニペット。GIF は起動時に一度だけデコードします。

Litestar Python

インストール
pip install "litestar[standard]"
ファイル
app.py
実行
litestar --app app:app run --port 8080
import base64

from litestar import Litestar, get
from litestar.datastructures import CacheControlHeader

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


@get(
    "/pixel.gif",
    media_type="image/gif",
    cache_control=CacheControlHeader(no_store=True),
    include_in_schema=False,
)
async def pixel() -> bytes:
    return GIF


app = Litestar([pixel])

このスニペットは実行し、返されたバイト列を照合しました。

確認

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

公式サイト: Litestar

Python の他の例