Hello!
On Thu, Jul 25, 2013 at 4:35 PM, <
avi...@adallom.com> wrote:
> Hello,
>
> Currently, the only API to pass a request body to the ngx.location.capture
> is to pass the entire request body as a Lua string in the options
> dictionary.
>
> This means that if the main request needs to pass its own request body to
> the subrqeuest, it should first read the entire request body to the memory
> (using the various API the Lua module offers), and then pass it as an
> argument for ngx.location.catpure.
>
No, that's not the case. To quote the official documentation for
ngx.location.capture:
"When the body option is not specified, the POST and PUT subrequests
will inherit the request bodies of the parent request (if any)."
Please see
http://wiki.nginx.org/HttpLuaModule#ngx.location.capture
for more details :)
> I want to write a patch that enables the main request to pass its body to
> the subrequest transparently, meaning without reading it first.
No, it's required that only the main request reads the request body.
One should always ensure that no subrequest is trying to *read* the
request body because the behavior is undefined. IIRC, recent Nginx
core explicitly checks this case.
It's fine that we don't read the request body into the Lua land in
your main request's Lua handler. But we should never never let the
subrequest actually read the request body from the system socket
receive buffers.
> The API should be rather simple, first of all, it means that the main
> request shouldn't read the body at all and that the lua_need_request_body
> directive should be set to "off". Then, the API would look something like
> that:
>
> result = ngx.location.capture("subrequest_location", {parent_request_body =
> true}).
>
> Does anyone have any suggestions regarding how such a patch can be
> implemented?
I'd rather accept a new option that makes the subrequest inherit its
parent's already-read request bodies even if the request method is not
POST nor PUT.
Best regards,
-agentzh