Trouble getting the Request Body of a HTTP Post

Maxim Dounin mdounin at mdounin.ru
Thu Dec 17 20:37:51 MSK 2009


Hello!

On Thu, Dec 17, 2009 at 11:35:16AM -0500, Tronman wrote:

> I recently created a custom Nginx module, and successfully compiled it into the Nginx source and used a location directive to direct traffic to my module (good job me).
> 
> In my modules handler, I of course have access to the ngx_http_request_t *r object passed into the function.

[...]

> So ultimately it comes down to:
> 1. Why isn't the response body in r->response_body like I would expect?

Your expectation is wrong.  Handler functions are called before 
request body has been read from client.

If you expect request body and want to read it, you should use 
ngx_http_read_client_request_body().

> 2. Would it be safe to access it by looking past request_line.data, and if so, how do I know the total header length?

No.

> 3. Is there another method I should be using to access the response body?

You mean request body?  Use ngx_http_read_client_request_body().

> 3. Any other advice you might have would be welcome!

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.

Maxim Dounin



More information about the nginx mailing list