lua possibilities/limitations

Richard Kearsley Richard.Kearsley at m247.com
Tue Feb 15 02:46:48 MSK 2011


Thanks for the help guys, I'm getting somewhere now, config file feels so script like it's an easy trap to fall in to :)
Please consider this example..

location /main {
set $myvar '';
set $limit_rate 99;
content_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.myvar = v
                                                                ngx.var.limit_rate = v
                                                 end
                                end
                                return
else
        ngx.exit(res.status)
end
';

add_header X-Test $myvar;
add_header X-Limit $limit_rate;

}

curl -I http://localhost:101/main
HTTP/1.1 200 OK
Server: nginx/0.8.54
Date: Mon, 14 Feb 2011 23:40:06 GMT
Content-Type: application/octet-stream
Connection: keep-alive
X-Test: 100
X-Limit: 99

Is there something special with $limit_rate stopping me to set it? Is it a string/int issue?



Regards,
Richard Kearsley


From: Eugaia [mailto:ngx.eugaia at gmail.com]
Sent: 14 February 2011 10:35
To: nginx at nginx.org
Subject: Re: lua possibilities/limitations

Hi,

...
On 13/02/2011 06:02, Richard Kearsley wrote:
location /main {
set $myvar '';
set $limit_rate 99;
...

set $limit_rate $myvar;
As well as the points agentzh made, there is also the case here that $limit_rate does a check on the values that it is set to, and it must be a valid size (internally this is done by having a set_handler attached to the variable - something most variables don't have).

Here, you are trying to set it to '' (i.e. empty), and this is invalid, and it will :
(a) throw an error in the error log, saying that it's an 'invalid size'
(b) do nothing to the value, therefore leaving it at 99 rather than setting it to ''

With the config you have, most variables would result in your headers being
...
X-Test: 100
X-Limit:

But you see X-Limit: 99 because of this reason.

Cheers,

Marcus.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20110214/e991d729/attachment-0001.html>


More information about the nginx mailing list