ngx.location.capture_multi multiple posts

agentzh agentzh at gmail.com
Wed Jun 20 06:32:31 UTC 2012


Hello!

On Tue, Jun 19, 2012 at 10:23 PM, Matthias Rieber <ml-nginx at zu-con.org> wrote:
> I try to use ngx.location.capture_multi to send multiple post requests:
>
[...]
>      content_by_lua '
>        upstream_servers = {{"/server1", {copy_all_vars = true, method =
> ngx.HTTP_POST}},
>                            {"/server2", {copy_all_vars = true, method =
> ngx.HTTP_POST}},
>                            }

Here, you let the subrequests all inherit the request body of the
current request but one gotcha here is that the current request's body
can be consumed only once. So you have the following options:

1. Read the entire request body into memory or your custom file using
ngx_lua's ngx.req.get_body_data or ngx.req.get_body_file API, and then
feed that to your subrequest by specifying the "body" option value.

2. Read the request body in a streaming fashion by means of the
"downstream cosocket" object returned by ngx.req.socket(), and send
the data chunk received to multiple backend HTTP connections at the
same time by means of the "upstream cosocket" returned by
ngx.socket.tcp(). In this approach, you'll no longer use ngx_proxy.

Best regards,
-agentzh



More information about the nginx mailing list