emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Starlette Python

Snippet Python untuk Starlette yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Starlette Python

Instal
pip install starlette uvicorn
File
app.py
Jalankan
uvicorn app:app --port 8080
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)])

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: Starlette

Lainnya dalam Python