emptygif
言語: 日本語

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

Google Cloud Run functions (Python) Python

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

Google Cloud Run functions (Python) Python

インストール
pip install functions-framework
ファイル
main.py
実行
functions-framework --target=pixel --port=8080
import base64

import functions_framework

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


@functions_framework.http
def pixel(request):
    if request.path != "/pixel.gif":
        return "Not Found", 404
    return GIF, 200, {"Content-Type": "image/gif", "Cache-Control": "no-store"}

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

確認

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

公式サイト: Google Cloud Run functions (Python)

Python の他の例