Rewrite response body

40 views
Skip to first unread message

Jake Pearson

unread,
Apr 9, 2018, 1:36:13 PM4/9/18
to openresty-en
Hi,
I am new to openresty and am trying to replace the body the comes from an earlier call to proxy_pass with code like this:

body_filter_by_lua_block {
ngx.arg[1] = '{"count"' .. ":2}'
ngx.arg[2] = true
}
I had originally, not had the line for `ngx.arg[2] = true`, but I would get back the body twice (does that mean the body I'm replacing has 2 chunks?). I added in the `ngx.arg[2] = true` line and now the output from the request looks good. When I deploy the `nginx` file, the service looks good for a few requests then the `nginx` requests start to hang. Is the correct/best practice for replacing the response body? What should I do instead?

Thanks,
Jake

FQ Liu

unread,
Apr 9, 2018, 9:25:32 PM4/9/18
to openresty-en
May be you should remove the Content-Length in response headers

在 2018年4月10日星期二 UTC+8上午1:36:13,Jake Pearson写道:

tokers

unread,
Apr 9, 2018, 9:50:10 PM4/9/18
to openresty-en
Hello!

The document already marked:

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
 

Jake Pearson

unread,
Apr 11, 2018, 9:40:07 AM4/11/18
to openresty-en
That took care of the problem. Thanks!
Reply all
Reply to author
Forward
0 new messages