Welcome! Log In Create A New Profile

Advanced

Re: How to merge subrequest header.

agentzh
November 25, 2010 05:24AM
On Wed, Nov 24, 2010 at 9:00 PM, Roast <zhang.libing@gmail.com> wrote:
> Hi,all.
>
> I use ngx_http_subrequest to send a subrequest with the parent's response
> body,after the sub request processed, I got the subrequest's body, but It
> seems has no way to merge the subrequest header to parent request.
>

You can register a post_subrequest callback function to your
ngx_http_subrequest call and do subrequest header processing there.

> Anybody else has met this same problem, and how to do this?
>

You can check out the corresponding code in our ngx_echo or ngx_lua
module. There's a live example for merging subrequest headers and body
into the main request in ngx_lua (untested though, but *should* work):

location /proxy {
proxy_pass http://foo.bar.com/$query_string;
}

location /main {
content_by_lua '
var res = ngx.location.capture("/proxy",
{ args = "/foo/bar/baz" }
)
if res.status == ngx.HTTP_OK then
for k,v in pairs(res.header) do
ngx.header[k] = v
end
ngx.print(res.body)
else
ngx.exit(res.status)
end
';
}

Cheers,
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to merge subrequest header.

Roast November 24, 2010 08:08AM

Re: How to merge subrequest header.

Roast November 24, 2010 08:02PM

Re: How to merge subrequest header.

agentzh November 25, 2010 05:24AM

Re: How to merge subrequest header.

agentzh November 25, 2010 05:34AM

Re: How to merge subrequest header.

Roast November 25, 2010 05:44AM

Re: How to merge subrequest header.

agentzh November 25, 2010 06:26AM

Re: How to merge subrequest header.

edo888 February 25, 2012 07:02PM

Re: How to merge subrequest header.

agentzh February 27, 2012 04:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 315
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready