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

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:

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:

May be I need to use ngx_http_write_request_body(sr,
sr->request_body->buffs)?

Posted at Nginx Forum:

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: