On Tue, May 1, 2012 at 4:44 AM, Roman Shishkin <r.sh...@gmail.com> wrote:
> I'v done test setup:
>
> location /proxy-pass {
> proxy_set_header Host $host;
> proxy_pass http://gymboree$request_uri;
> }
>
> location / {
> content_by_lua '
> res = ngx.location.capture("/proxy-pass");
> -- ngx.say(res.header)
> ngx.print(res.body)
> ';
>
> If I uncoment ngx.say(res.header) I'v got an error in nginx log:
>
> *137 lua handler aborted: runtime error: [string "content_by_lua"]:5: bad ar
> gument #1 to 'print' (on-array table found) while sending to client
>
Because the ngx.header value is a Lua table. And the Lua table is not
an array-like table. You cannot feed it directly into ngx.print nor
ngx.say because these methods do not support that.
> Also I'v got an error message in browser if acces to / of my site:
> Resource interpreted as Document but transferred with MIME type
> application/x-gzip:
>
The subrequest's response headers are not forwarded to the parent
request because you can issue multiple subrequests and you need finer
control here.
If you want to forward the subrequests' response headers, you need to
forward them to the main request yourself, i.e., iterating through the
res.header table and set each header entry to the ngx.header special
table, see
http://wiki.nginx.org/HttpLuaModule#ngx.header.HEADER
> If i try to get /proxy-pass directly - all works fine.
>
> It looks like ngx.location.capture lost original headers in response
> Is it a bug, or some kind of magic?
>
It is by design :)
Best regards,
-agentzh
P.S. I've cc'd the openresty mailing group:
https://groups.google.com/group/openresty so that other people can see
our discussion here :)