<br><br><div class="gmail_quote">On Mon, May 10, 2010 at 6:41 PM, Maxim Dounin <span dir="ltr">&lt;<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Hello!<br>
<div><br>
On Fri, May 07, 2010 at 03:38:54PM -0700, Matthieu Tourne wrote:<br>
<br>
&gt; I&#39;m trying to send a POST Subrequest using the same request_body as the<br>
&gt; Parent Request.<br>
&gt; The subrequest is sent first, and once it has been finalized the parent<br>
&gt; request goes through.<br>
&gt; (this is inspired on Maxim&#39;s ngx_http_auth_request_module)<br>
&gt;<br>
&gt; It works almost fine, but if I try to make this subrequest to a location<br>
&gt; containing a proxy_pass, I get some weird behavior. (The connection takes<br>
&gt; forever to terminate).<br>
&gt;<br>
&gt; My guess is that the request_body gets read by the upstream, and discarded.<br>
&gt; When the parent request goes through, that data is not available anymore.<br>
<br>
</div>If you issue subrequest before request body was read by main<br>
request, you likely get SIGSEGV on an attempt to read it.  If you<br>
didn&#39;t - you probably just didn&#39;t used -DDEBUG_MALLOC while<br>
compiling nginx (or appropriate malloc options in your OS).  It&#39;s<br>
only possible to read request body in main request.<br>
<div><br>
&gt; If I create a dummy request_body for the subrequest with temporary buffers,<br>
&gt; it seems to work fine.<br>
&gt;<br>
&gt; I think I might be able to get around this by reading first the original<br>
&gt; request_body using ngx_http_read_client_request_body(),<br>
&gt; and then copying the content of r-&gt;request_body to temporary buffers in my<br>
&gt; subrequest.<br>
<br>
</div>There is no good/reliable way to preserve request body and use it<br>
for two upstream requests.  There are no problems with in-memory<br>
buffer (at least I&#39;m not aware of), but once your request body is<br>
buffered to temporary file - it will be released by first<br>
successful upstream request (see ngx_http_upstream_send_response()<br>
in ngx_http_upstream.c).<br>
<br>
Using dupfd() on temporary file descriptor may be an option, but<br>
it&#39;s your responsibility to do it properly.<br>
<font color="#888888"><br>
Maxim Dounin<br>
</font><div><div></div><div><br></div></div></blockquote><div><br></div><div>Hi,</div><div><br></div><div>So the way I solved this is to make a full copy of r-&gt;request_body into temporary bufs of the subrequest.</div>


<div><br></div><div>I would create a subrequest using ngx_http_subrequest(), </div><div>then use ngx_http_read_client_request_body(r, post_handler), to read r-&gt;request_body and set a  function to copy it in the subrquest as the post_handler.</div>


<div><br></div></div><div>I was wondering if this could be dangerous, if the subrequest could be fired before r-&gt;request_body would be completely read, or is it done in a sequential order ?</div><div><br></div><div>Concerning malloc, is :</div>


<div>env MALLOC_OPTIONS=J;</div><div>in nginx.conf sufficient ?</div><div><br></div><div>Also, is it possible to something such as Valgrind on nginx workers ?</div><div><br></div><div>Thank you,</div><div><br></div><div>

Matthieu.</div><br>-- <br>Matthieu Tourne<br>