emptygif
語言: 繁體中文

所有語言和框架

OpenResty (Lua) Lua

適用於 OpenResty (Lua) 的 Lua 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,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)