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:
- Getting the request headers (r->headers_in)
- Setting and sending the response headers (r->headers_out,
ngx_http_send_header(r) - 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:
- I run nginx
- I telnet to my localhost at port 80
- 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:
- Why isnât the response body in r->response_body like I would expect?
- Would it be safe to access it by looking past request_line.data, and
if so, how do I know the total header length? - Is there another method I should be using to access the response
body? - Any other advice you might have would be welcome!
Thanks.
Posted at Nginx Forum: