-- body_filter_by_lua_file test.lua
if ngx.header.content_encoding:lower() == "gzip" then
local res, eof = ngx.arg[1], ngx.arg[2]
local zlib = require "zlib"
-- 解压
res = zlib.inflate()(res)
ngx.log(ngx.INFO, 'inflate res:'..res)
-- 替换
res = string.gsub(res, 'aaa', 'bbb')
-- 压缩
res = zlib.deflate()(res, 'sync')
ngx.log(ngx.INFO, 'deflate res:'..res)
ngx.arg[1] = res
end