emptygif
言語: 日本語

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

OpenResty (Lua) Lua

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

OpenResty (Lua) Lua

ファイル
nginx.conf
実行
openresty -s reload
http {
    init_by_lua_block {
        -- decoded once, when the master process loads the config
        PIXEL_GIF = ngx.decode_base64("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==")
    }

    server {
        listen 8080;

        location = /pixel.gif {
            content_by_lua_block {
                ngx.header["Content-Type"] = "image/gif"
                ngx.header["Content-Length"] = #PIXEL_GIF
                ngx.header["Cache-Control"] = "no-store"
                ngx.print(PIXEL_GIF)
            }
        }
    }
}

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

確認

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

公式サイト: OpenResty (Lua)