2

I use Nginx + lua module and body_filter_by_lua directive.

Nginx-lua docs said

When the Lua code may change the length of the response body, then it is required to always clear out the Content-Length response header (if any) in a header filter to enforce streaming output.

ngx.header.content_length = nil
  1. Could it break keepalive connections?
  2. Could it break requests on problematic channels?
  3. How client will know that data is completely read from server?
  4. Why Nginx does not forces Transfer-Encoding: chunked for this responses?

Update.

As a temporary solution i convert response to a chunked via

ngx.header['Content-Type'] = "text/html"
ngx.header['Content-Length'] = nil
ngx.header['Transfer-Encoding'] = 'chunked'

and in content-rewrite phase

-- Length of current chunk.
local hexlen = string.format("%x", #ngx.arg[1])
ngx.arg[1] = hexlen .. "\r\n" .. ngx.arg[1] .. "\r\n"

-- Last chunk. Send final sequence.
if (ngx.arg[2]) then
    ngx.arg[1] = ngx.arg[1] .. "0\r\n\r\n"
end

Update 2.

Use ngx.location.capture!

Pavel Patrin
  • 1,630
  • 1
  • 19
  • 33

0 Answers0