Trouble getting the Request Body of a HTTP Post
nginx-forum at nginx.us
Thu Dec 17 19:35:16 MSK 2009
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
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!
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,31312,31312#msg-31312
More information about the nginx