Welcome! Log In Create A New Profile

Advanced

Re: How to merge subrequest header.

agentzh
November 25, 2010 05:34AM
On Thu, Nov 25, 2010 at 6:18 PM, agentzh <agentzh@gmail.com> wrote:
> 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):
>

Sorry, the previous sample has bugs. The following example is tested
and working:

location /proxy {
proxy_pass http://www.baidu.com/s;
}

location /main {
content_by_lua '
local res = ngx.location.capture("/proxy",
{ args = { wd = "Perl" } }
)

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
';
}

I used the following command line to test the /main location to check
the response body:

curl localhost/main|grep Perl|iconv -f gbk -t utf8

and the following command to check the response headers:

$ curl -I localhost/main
HTTP/1.1 200 OK
Server: nginx/0.8.41
Date: Thu, 25 Nov 2010 10:30:12 GMT
Content-Type: text/html;charset=gbk
Connection: keep-alive
Content-Length: 32274
Cache-Control: private
Set-Cookie: BAIDUID=F8A74DD5F378F2EFFEA0EC6B8BD10E1B:FG=1;
expires=Thu, 25-Nov-40 10:30:11 GMT; path=/; domain=.baidu.com
P3P: CP=" OTI DSP COR IVA OUR IND COM "

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