Forum: NGINX How do i get the request body ?

2974d09ac2541e892966b762aad84943?d=identicon&s=25 humank (Guest)
on 2014-01-02 05:45
(Received via mailing list)
Hello guys,

        I'm developing a nginx module, the intent is to get the request
body, then write some response depends on what request body is.
        I've called the method ngx_http_read_client_request_body (r,
ngx_http_myModule_handler);

        Since this code, i want to get the real request body in
ngx_http_myModule_handler()
        Here are my codes ...

        void ngx_http_myModule_handler(ngx_http_request_t *r)
{
    ngx_http_finalize_request(r, NGX_DONE);

    if(!(r->request_body->bufs == NULL)){
        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "request is
not
empty.");

    }
}

     the questions is , how can i get the r->request_body->bufs to char
* ?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,245952,245952#msg-245952
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2014-01-03 04:41
(Received via mailing list)
Hello!

On Wed, Jan 01, 2014 at 11:44:24PM -0500, humank wrote:

>
>
>      the questions is , how can i get the r->request_body->bufs to char * ?

A request body is available as a series of
buffers in r->request_body->bufs.  To understand more about
buffers, try reading Evan Miller's guide as available from here:

http://www.evanmiller.org/nginx-modules-guide.html

Some example code which uses r->request_body->bufs to access
request body contents as available in memory can be found in
src/http/ngx_http_variables.c, in the
ngx_http_variable_request_body() function.

Note though, that depending on a configuration and a request, the
request body may not be available in memory at all (that is, it
will be in temporary file, and there will be a file buffer in
r->request_body->bufs).

--
Maxim Dounin
http://nginx.org/
2974d09ac2541e892966b762aad84943?d=identicon&s=25 humank (Guest)
on 2014-01-09 06:52
(Received via mailing list)
Maxim Dounin Wrote:
-------------------------------------------------------
> > ngx_http_myModule_handler);
> >         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "request
> buffers in r->request_body->bufs.  To understand more about
> request body may not be available in memory at all (that is, it
> http://mailman.nginx.org/mailman/listinfo/nginx
Hi Maxim,
    Thanks for your reply, i have get the body from the sample code
src/http/ngx_http_variables.c.
    Next time i will try to grep all the source code first while facing
the
unknown problems :D

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,245952,246137#msg-246137
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.