Skip to content

Instantly share code, notes, and snippets.

@enginyoyen
enginyoyen / example.com
Last active December 16, 2019 20:10
[Nginx Body Filter] #nginx
server {
set $response_body ''; #we must declare variables first, we cannot create vars in lua
set $error_request_body '';
set $error_response_body '';
body_filter_by_lua '
local resp_body = string.sub(ngx.arg[1], 1, 1000) -- arg[1] contains a chunk of response content
ngx.ctx.buffered = string.sub((ngx.ctx.buffered or "") .. resp_body, 1, 1000)
if ngx.arg[2] then -- arg[2] is true if this is the last chunk
ngx.var.response_body = ngx.ctx.buffered
end