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)