1、下载和安装lua_zlib
wget https://github.com/brimworks/lua-zlib/archive/master.zip unzip master.zip cd lua-zlib-master cmake -DLUA_INCLUDE_DIR=/usr/local/openresty/luajit/include/luajit-2.1 make cp zlib.so /usr/local/openresty/lualib/zlib.so
注:安装lua_zlib需要lua或luajit的支持,所以在cmake时需要指定lua的路径。
2、使用lua_zlib来接收gzip请求
local zlib = require "zlib" local encoding = ngx.req.get_headers()["Content-Encoding"] ngx.req.read_body(); if encoding == "gzip" then local body = ngx.req.get_body_data() if body then local stream = zlib.inflate() ngx.req.set_body_data(stream(body)) end end
时间: 2024-11-08 23:05:35