Subrequest using Parent Request Body

Maxim Dounin mdounin at
Thu May 13 01:22:30 MSD 2010


On Wed, May 12, 2010 at 12:15:22PM -0700, Matthieu Tourne wrote:


> So the way I solved this is to make a full copy of r->request_body into
> temporary bufs of the subrequest.
> I would create a subrequest using ngx_http_subrequest(),
> then use ngx_http_read_client_request_body(r, post_handler), to read
> r->request_body and set a  function to copy it in the subrquest as the
> post_handler.
> I was wondering if this could be dangerous, if the subrequest could be fired
> before r->request_body would be completely read, or is it done in a
> sequential order ?

You have to read body and call ngx_http_subrequest() only when 
it's fully read (i.e. from post_handler).

> Concerning malloc, is :
> in nginx.conf sufficient ?

No.  Under FreeBSD nginx respects MALLOC_OPTIONS=J in environment 
and activates the same logic as with -DNGX_DEBUG_MALLOC, but it 
has to be already set at master process startup.

On other OSes the only available option is 
./configure --with-cc-opts="-D NGX_DEBUG_MALLOC".

> Also, is it possible to something such as Valgrind on nginx workers ?

Never tried.  Though you may disable daemon mode and master process 
completely with "daemon off; master_process off;".  This turns 
nginx into simple single-process programm which may be 
debugged/profiled by almost anything.  There are some limitations 
(reconfiguration and binary update doesn't work), but they are 

Maxim Dounin

More information about the nginx mailing list