# Subrequest and POST

**URL:** <https://www.ruby-forum.com/t/subrequest-and-post/208302>\
**Category:** NGINX\
**Created:** [June 14, 2011, 7:45pm UTC](https://www.ruby-forum.com/t/subrequest-and-post/208302 "2011-06-14T19:45:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 14, 2011, 7:45pm UTC](https://www.ruby-forum.com/t/subrequest-and-post/208302/1 "2011-06-14T19:45:42Z")

</div>

Hi,

I’m writing code, which making decision to accept or not rest of request  
in NGINX. For that I’ve created 2 modules, one subrequest module,  
another one accepting “client\_max\_body\_size\_var”.

Everything works fine, except POST data, I can get result of subrequest  
only when POST finished,  
can I get subrequest data before accepting or declining request\_body?

Regards  
Roman V.

---

<div class="post-metadata">

**Author:** ![Roman\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@Roman\_V](https://www.ruby-forum.com/u/Roman_V)\
**Post date:** [June 15, 2011, 1:37am UTC](https://www.ruby-forum.com/t/subrequest-and-post/208302/2 "2011-06-15T01:37:21Z")

</div>

Hi,

Whan to add that fixed it by removing all headers from main request.

```
     sr->headers_in.headers.part.nelts=0;

```

Is it correct? Or exists more clear way to do that?

---

<div class="post-metadata">

**Author:** ![Roman\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@Roman\_V](https://www.ruby-forum.com/u/Roman_V)\
**Post date:** [June 15, 2011, 1:39am UTC](https://www.ruby-forum.com/t/subrequest-and-post/208302/3 "2011-06-15T01:39:12Z")

</div>

On 06/14/2011 04:35 PM, Roman V. wrote:

> Hi,
> 
> Whan to add that fixed it by removing all headers from main request.  
> Sorry, removing from _subrequest_.

---

<div class="post-metadata">

**Author:** ![Roman\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@Roman\_V](https://www.ruby-forum.com/u/Roman_V)\
**Post date:** [June 15, 2011, 2:02am UTC](https://www.ruby-forum.com/t/subrequest-and-post/208302/4 "2011-06-15T02:02:36Z")

</div>

Hello!

On Tue, Jun 14, 2011 at 04:37:08PM -0700, Roman V. wrote:

> On 06/14/2011 04:35 PM, Roman V. wrote:
> 
> > Hi,
> > 
> > Whan to add that fixed it by removing all headers from main request.  
> > Sorry, removing from _subrequest_.
> > 
> > ```
> > sr->headers_in.headers.part.nelts=0;
> > 
> > ```
> > 
> > Is it correct? Or exists more clear way to do that?

This isn’t correct (in both meanings: it doesn’t correctly remove  
headers from subrequest and not a correct way to prevent body from  
being read before subrequest).

I would recommend adding fake body to subrequest instead, see  
example here:

> **[ngx\_http\_auth\_request\_module: a29d74804ff1 ngx\_http\_auth\_request\_module.c](http://mdounin.ru/hg/ngx_http_auth_request_module/file/a29d74804ff1/ngx_http_auth_request_module.c#l193)**

Note that it may be also needed to instruct backend to not expect  
body, i.e. if you proxy\_pass such subrequest you should either use

```
proxy_pass_request_headers off;

```

or

```
proxy_set_header Content-Length "";

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![Roman\_V](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bc8723/32.png) [@Roman\_V](https://www.ruby-forum.com/u/Roman_V)\
**Post date:** [June 16, 2011, 1:29am UTC](https://www.ruby-forum.com/t/subrequest-and-post/208302/5 "2011-06-16T01:29:59Z")

</div>

Thank you,  
it was very helpful.
