# How to make a post subrequest with response body from parent?

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-post-subrequest-with-response-body-from-parent/217252>\
**Category:** NGINX\
**Created:** [February 26, 2012, 1:06am UTC](https://www.ruby-forum.com/t/how-to-make-a-post-subrequest-with-response-body-from-parent/217252 "2012-02-26T01:06:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 26, 2012, 1:06am UTC](https://www.ruby-forum.com/t/how-to-make-a-post-subrequest-with-response-body-from-parent/217252/1 "2012-02-26T01:06:46Z")

</div>

Hi,

I want to make a post subrequest to fastcgi with parent’s response body  
to filter it there and return to client.

I cannot find any manual about making a post subrequests. Can you share  
some basic code with explanation?

Thanks in advance.

Posted at Nginx Forum:

> **[How to make a post subrequest with response body from parent?.](https://forum.nginx.org/read.php?2,222983,222983#msg-222983)**
>
> Hi, I want to make a post subrequest to fastcgi with parent's response body to filter it there and return to client. I cannot find any manual about making a post subrequests. Can you share some basic code with explanation? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![edo888](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/aeb1de/32.png) [@edo888](https://www.ruby-forum.com/u/edo888)\
**Post date:** [February 27, 2012, 2:16am UTC](https://www.ruby-forum.com/t/how-to-make-a-post-subrequest-with-response-body-from-parent/217252/2 "2012-02-27T02:16:03Z")

</div>

Digging around I was able to get this code so far:

in my module’s body filter I do this:

if(ngx\_http\_subrequest(r, &uri, &query\_string, &sr, NULL, 0) != NGX\_OK)  
return NGX\_ERROR;

// adjust subrequest  
ngx\_str\_t method\_name = ngx\_string(“POST”);  
sr-\>method = NGX\_HTTP\_POST;  
sr-\>method\_name = method\_name;

First of all it still uses GET with fastcgi\_pass. If I do proxy\_pass  
instead the method is POST. I think it is a bug in fastcgi module. The  
above code should be OK so far, since it works with proxy\_pass.

Now I don’t know how to pass post data to subrequest. I have tried to  
create a buffer chain with sample data in it and using  
sr-\>request\_body-\>bufs, however it doesn’t work.

Am I right that if I populate sr-\>request\_body-\>bufs they will be  
written to subrequest request body?

Posted at Nginx Forum:

> **[Re: How to make a post subrequest with response body from parent?.](https://forum.nginx.org/read.php?2,222983,223023#msg-223023)**
>
> Hi, I want to make a post subrequest to fastcgi with parent's response body to filter it there and return to client. I cannot find any manual about making a post subrequests. Can you share some basic code with explanation? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![edo888](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/aeb1de/32.png) [@edo888](https://www.ruby-forum.com/u/edo888)\
**Post date:** [February 27, 2012, 2:27am UTC](https://www.ruby-forum.com/t/how-to-make-a-post-subrequest-with-response-body-from-parent/217252/3 "2012-02-27T02:27:45Z")

</div>

May be I need to use ngx\_http\_write\_request\_body(sr,  
sr-\>request\_body-\>buffs)?

Posted at Nginx Forum:

> **[Re: How to make a post subrequest with response body from parent?.](https://forum.nginx.org/read.php?2,222983,223024#msg-223024)**
>
> Hi, I want to make a post subrequest to fastcgi with parent's response body to filter it there and return to client. I cannot find any manual about making a post subrequests. Can you share some basic code with explanation? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![edo888](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/aeb1de/32.png) [@edo888](https://www.ruby-forum.com/u/edo888)\
**Post date:** [February 27, 2012, 8:29pm UTC](https://www.ruby-forum.com/t/how-to-make-a-post-subrequest-with-response-body-from-parent/217252/4 "2012-02-27T20:29:59Z")

</div>

Hi,

Just in case someone will find this in google. I have found a solution.

You will need to populate sr-\>request\_body-\>bufs and then make sure to  
set sr-\>headers\_in.content\_length\_n…

You can check the http echo module subrequest.c file and see how it sets  
the content length.

Posted at Nginx Forum:

> **[Re: How to make a post subrequest with response body from parent?.](https://forum.nginx.org/read.php?2,222983,223071#msg-223071)**
>
> Hi, I want to make a post subrequest to fastcgi with parent's response body to filter it there and return to client. I cannot find any manual about making a post subrequests. Can you share some basic code with explanation? Thanks in advance.
