Disable chunked transfer encoding for lua output

1,040 views
Skip to first unread message

shairon toledo

unread,
Mar 4, 2013, 2:24:26 PM3/4/13
to openre...@googlegroups.com
Hi guys,

I'm trying to create a mock server with static response for an internal application, I've tried to disable chunked transfer encoding by 

          chunked_transfer_encoding off;

however the body is not available when I do that. I also tried set the content-length for it, no success too.




I was wondering if is possible to disable chunked response using lua content output.

Thx.

agentzh

unread,
Mar 4, 2013, 2:44:53 PM3/4/13
to openre...@googlegroups.com
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

shairon toledo

unread,
Mar 4, 2013, 3:03:06 PM3/4/13
to openre...@googlegroups.com
Thanks a lot Zhang, it did the trick!
Reply all
Reply to author
Forward
0 new messages