# How do i get the request body?

**URL:** <https://www.ruby-forum.com/t/how-do-i-get-the-request-body/238297>\
**Category:** NGINX\
**Created:** [January 2, 2014, 5:45am UTC](https://www.ruby-forum.com/t/how-do-i-get-the-request-body/238297 "2014-01-02T05:45:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [January 2, 2014, 5:45am UTC](https://www.ruby-forum.com/t/how-do-i-get-the-request-body/238297/1 "2014-01-02T05:45:04Z")

</div>

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:

> **[How do i get the request body ?](https://forum.nginx.org/read.php?2,245952,245952#msg-245952)**
>
> 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

---

<div class="post-metadata">

**Author:** ![humank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c4cdca/32.png) [@humank](https://www.ruby-forum.com/u/humank)\
**Post date:** [January 3, 2014, 4:41am UTC](https://www.ruby-forum.com/t/how-do-i-get-the-request-body/238297/2 "2014-01-03T04:41:23Z")

</div>

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 M.'s guide as available from here:

> **[Emiller’s Guide to Nginx Module Development](https://www.evanmiller.org/nginx-modules-guide.html)**
>
> Ever wanted to extend Nginx’s functionality with custom C code? This is the comprehensive guide that you need. Maintained since 2007.

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 D.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![humank](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c4cdca/32.png) [@humank](https://www.ruby-forum.com/u/humank)\
**Post date:** [January 9, 2014, 6:52am UTC](https://www.ruby-forum.com/t/how-do-i-get-the-request-body/238297/3 "2014-01-09T06:52:44Z")

</div>

## Maxim D. 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  
> > [mailman.nginx.org archive](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 😃

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,245952,246137#msg-246137](http://forum.nginx.org/read.php?2,245952,246137#msg-246137)
