emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Falcon Python

Ein Python-Snippet für Falcon, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Falcon Python

Installieren
pip install falcon uvicorn
Datei
app.py
Ausführen
uvicorn app:app --port 8080
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())

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Falcon

Mehr in Python