Welcome! Log In Create A New Profile

Advanced

Trouble getting the Request Body of a HTTP Post

December 17, 2009 11:35AM
Hi there,

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.

Using this object, I have no trouble:

1. Getting the request headers (r->headers_in)
2. Setting and sending the response headers (r->headers_out, ngx_http_send_header(r);)
3. Send response body (return ngx_http_output_filter(r, &out);)

However, I'm having a very difficult time accessing the request body. Let me explain:

1. I run nginx
2. I telnet to my localhost at port 80
3. I enter something like this:

POST /mylocation HTTP/1.0
Host: 127.0.0.1
Content-Length: 13
value=Tronman

But in my hander function,
r->request_body is completely null!

However, I know the body is being read since if I look at "r->request_line.data" and simply offset the pointer by the length of the headers, I clearly see the "value=Tronman". But I don't feel this is a very safe thing to do unless I can always be sure that the Request Body will indeed be accessible this way and I know the total length of the headers. I'm not making any calls to ngx_http_discard_request_body(r); in the handler or anywhere else I'm aware of.

I also tried using the ngx_http_read_client_request_body, but this ultimately just makes r->request_header->buf point to gibberish. I used gdb to trace through the code and it ultimately leads to a failed "recv" socket function, for which the failure would make sence if the body had already been read (which it seems to have been).

A few other details:
System: Ubuntu 9.10 32-bit
Nginx Version: 0.7.64

So ultimately it comes down to:
1. Why isn't the response body in r->response_body like I would expect?
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?
3. Is there another method I should be using to access the response body?
3. Any other advice you might have would be welcome!

Thanks.
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: 88
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready