Subrequest request body streaming

John Doe muffinmonster64 at
Fri Apr 8 15:26:02 UTC 2016

Hi All,

I'm writing a content phase handler module, which executes sub requests to
an internal location in my nginx config, and in specific, a proxy_pass. It
also modifies headers, request body, and response body as the request
streams through.

location / {

location /internal {
  proxy_pass http://....

GET requests work ok, but for PUT, the entire body has to first be read in
by my module, because request_body_no_buffering does not work for sub

I got around this for the PUT sub request  by adding a flag
to ngx_connection_t, wrapping the ngx_connection_t ->recv function with my
own function, and finally modifying the sub request check
in ngx_http_read_client_request_body to be ignored if my flag is set.

The recv wrapper is necessary, because the content length header in the sub
request is larger than the content length in the main request,
and ngx_http_request_body.c does its accounting based on the recv function,
and not ngx_http_top_request_body_filter.

Is there a better way of doing this?

Any feedback or suggestions would be greatly appreciated.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx-devel mailing list