Welcome! Log In Create A New Profile

Advanced

Re: lua possibilities/limitations

agentzh
July 04, 2011 05:32AM
On Tue, Feb 15, 2011 at 12:27 PM, agentzh <agentzh@gmail.com> wrote:
> On Tue, Feb 15, 2011 at 7:46 AM, Richard Kearsley
> <Richard.Kearsley@m247.com> wrote:
>>
>> Is there something special with $limit_rate stopping me to set it? Is it a
>> string/int issue?
>>
>
> Yeah, $limit_rate is a special variable defined in the http core module:
>
>    http://wiki.nginx.org/NginxHttpCoreModule#.24limit_rate
>
> For now, ngx_lua's "ngx.var.foo = xxx" assignment does not support
> such special variables. This will change in a future release.
>

I've just committed a fix for nginx variable assignment in Lua to
ngx_lua's git master HEAD. Now all the nginx variables with a
set_handler is properly handled (like $args and $limit_rate).
Furthermore, only changeable nginx variables will be honored, so
writing to $arg_PARAM will result in a Lua exception (ready to be
caught by pcall/xpcall if LuaJIT 2.0 is used).

Here's the modified version of your sample config that should work for you:

location /proxy {
proxy_pass http://127.0.0.1:8012/;
}

location /main {
set $limit_rate 99;
rewrite_by_lua '
local res = ngx.location.capture("/proxy",{ args = { bla =
"moo" } })
if res.status == ngx.HTTP_OK then
for k,v in pairs(res.header) do
if k == "X-Limit-Rate" then
ngx.var.limit_rate = v
end
end

return
end

ngx.exit(res.status)
';

add_header X-Limit $limit_rate;
}

My modifications mainly correct the following mistake in your previous sample:

* content_by_lua always runs in the content phase while ngx_rewrite's
"set" command always runs at the earlier rewrite phase. So your
content_by_lua will always run *after* your "set" commands even if you
put it before them.

As a bonus, I also add reading support for nginx regex group capturing
variables like $1, $2, $3, and etc, in Lua.

Happy Lua hacking!

Best,
-agentzh

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

lua possibilities/limitations

Richard Kearsley February 13, 2011 01:16AM

Re: lua possibilities/limitations

agentzh February 13, 2011 11:12PM

Re: lua possibilities/limitations

agentzh February 13, 2011 11:18PM

Re: lua possibilities/limitations

Eugaia February 14, 2011 05:38AM

RE: lua possibilities/limitations

Richard Kearsley February 14, 2011 06:50PM

Re: lua possibilities/limitations

agentzh February 14, 2011 11:32PM

Re: lua possibilities/limitations

Eugaia February 15, 2011 04:02AM

Re: lua possibilities/limitations

agentzh February 15, 2011 05:50AM

Re: lua possibilities/limitations

agentzh July 04, 2011 05:32AM

RE: lua possibilities/limitations

Richard Kearsley July 04, 2011 08:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 204
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