It was not an issue related to neither Lua nor openResty, I just had to check what headers were used by the subrequest (transferred from the main request).
One of the headers sent by Chrome is "Accept-Encoding: gzip, deflate", so the response body was just zipped. I just had to add a line before the capture to change that :
access_by_lua_block {
ngx.req.set_header("Accept-Encoding", "")
local res = ngx.location.capture( '/authUser',
{ method = ngx.HTTP_POST,
body = '{request: "authenticated?"}'})
ngx.log(1, res.body)
ngx.log(1, res.status)
return(ngx.HTTP_OK)
}
The response body is now perfectly readable.
Seifallah Ben Abda
On Thursday, April 14, 2016 at 9:32:59 PM UTC+1, saifalla...@predictix.com wrote:
Hello everyone,
This might be an easy case as I am new to both Lua and nginx configuration. I searched around but still have no clue why this is happening.
I want to use location.capture to send a subrequest to eventually do some verification, but I have troubles displaying the response body of that request.
I am using this code in my config:
access_by_lua_block {
local res = ngx.location.capture( '/authUser',
{ method = ngx.HTTP_POST,
body = '{request: "authenticated?"}'})
ngx.log(1, res.body)
ngx.log(1, res.status)
return(ngx.HTTP_OK)
}
I call a service to trigger this block, and I get this on the log file:
2016/04/14 21:18:14 [emerg] 31335#0: *4 [lua] access_by_lua(nginx.conf:28):4: =�A
�0 Ы�_� �� � ����W�Tf Ļk7n �� 9+ ���C #��M?��4�H��j \�y�㖠F���Z��fu΅���X��5����Q�z\m while sending to client, client: 127.0.0.1, server: , request: "POST /getOperations HTTP/1.1", host: "localhost", referrer: "http://localhost/index.html"
2016/04/14 21:18:14 [emerg] 31335#0: *4 [lua] access_by_lua(nginx.conf:28):5: 200 while sending to client, client: 127.0.0.1, server: , request: "POST /getOperations HTTP/1.1", host: "localhost", referrer: "http://localhost/index.html"
The service answers properly but I am not able to display the body of the response. Knowing that when I send the exact same request with curl, I get a normal answer. Is this some kind of serialization proper to Lua? or am I missing something else?
Let me know if you need any additional details.
Thank you for your help.
Seifallah Ben Abda