Trouble getting the Request Body of a HTTP Post

Tronman nginx-forum at
Thu Dec 17 21:58:00 MSK 2009

Hi there, Thanks for your response!

I'm still trying to get the hang of the I/O model going on here. Bare with me to see if I understand:

When a connection comes in, the "ngx_http_my_module_handler" is called. This function has the request headers, but not the request body. In "ngx_http_my_module_handler", we can use "ngx_http_read_client_request_body(r, ngx_http_my_module_body_handler);" to set a callback (handler) to be run when the Request Body is read (yes, I did mean Request Body, sorry for my typo). Since the response is dependant on the body, "ngx_http_my_module_handler" really doesn't have to do anything else after setting the call back but return NGX_DONE.

Thus, when the function "ngx_http_my_module_body_handler" gets called, I've got both the original headers, and the request body, and it's here that I should place all of the logic to build my response and send it to the client.

This implies that the client program connecting to the server must use separate "send" calls to send the header first, then the body, and cannot put both a header and a body into the same buffer and send them at the same time. Is this the case? 

> To see the difference between (2) and (3) you may consider using
> some big POST (e.g. 10M) slowly uploaded by client. This also
> should give you some idea about how to handle multiple request
> body buffers and disk-buffered data.

In this case, what would be the order of function calls? For example, would "ngx_http_my_module_body_handler" be called for each piece of the body (which I would write my own logic to handle) or called after the entire (say 10M) body has been read. Is "ngx_http_my_module_handler" still called only once when the header arises?

In the meantime, I have moved my response generating logic into the "ngx_http_my_module_body_handler" which is working much better (for single chunk bodies at least). Also, when I was telnet-ing, I was trying to send headers and body in one chunk, which wasn't working. Instead I started sending them in separate chunks and am getting closer to the behaviour I expected. 

Thanks for your help!

Posted at Nginx Forum:,31312,31370#msg-31370

More information about the nginx mailing list