Hello!
On Mon, Mar 4, 2013 at 11:24 AM, shairon toledo wrote:
> however the body is not available when I do that. I also tried set the
> content-length for it, no success too.
>
Explicitly setting the Content-Length response header before sending
out the response headers should do the trick.
If it does not work for you, then please describe in exactly what way
it doesn't work and what you're getting in your nginx error log file.
A minimized sample that can reproduce this issue would also be useful.
On the other hand, simply saying "no success" does not help at all :)
I've tried the following small example on my side and it works as expected:
location = /t {
content_by_lua '
ngx.header.content_length = 12
ngx.say("hello")
ngx.say("world")
';
}
And using "curl --raw" can verify the raw response body:
$ curl --raw -i localhost:8080/t
HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Mon, 04 Mar 2013 19:40:03 GMT
Content-Type: text/plain
Connection: keep-alive
content-length: 12
hello
world
If we comment out the line "ngx.header.content_length = 12" in the
example above, we then get a chunked response body, also as expected:
$ curl --raw -i localhost:8080/t
HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Mon, 04 Mar 2013 19:41:39 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
6
hello
6
world
0
As we can see, the "curl" utility is handy while debugging HTTP services ;)
Best regards,
-agentzh