Welcome! Log In Create A New Profile

Advanced

Re: Trouble getting the Request Body of a HTTP Post

December 17, 2009 01:58PM
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!
Subject Author Posted

Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 11:35AM

Re: Trouble getting the Request Body of a HTTP Post

Maxim Dounin December 17, 2009 12:44PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 01:58PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 02:28PM

Re: Trouble getting the Request Body of a HTTP Post

Maxim Dounin December 17, 2009 02:32PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 17, 2009 03:33PM

Re: Trouble getting the Request Body of a HTTP Post

barretto_chris February 08, 2011 06:38PM

Re: Trouble getting the Request Body of a HTTP Post

Nick Pearson December 17, 2009 03:50PM

Re: Trouble getting the Request Body of a HTTP Post

Maxim Dounin December 17, 2009 05:02PM

Re: Trouble getting the Request Body of a HTTP Post

Tronman December 18, 2009 08:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 180
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready