Order arguments after ngx.req.set_uri_args()

63 views
Skip to first unread message

Rainer Canavan

unread,
Jul 5, 2022, 9:56:44 AM7/5/22
to openre...@googlegroups.com
Hi,

We are using openresty as a reverse proxy, and with 1.17.8.2, we used
to remove a query argument from requests to improve the cache hit rate
of the varnish that sits between openresty and the slow source server.
The code we used in access_by_lua was the following:

if (string.match(ngx.var.uri, '^/cms/')) then
if ngx.var.QUERY_STRING then
local args = ngx.req.get_uri_args()
if args.click ~= nil then
args.click = "removed"
ngx.req.set_uri_args(args)
end
end
end

That used to work splendidly, with respectable cache hit rates way
above 90%. After an upgrade to openresty 1.19.9.1, the cache hit rate
has dropped dramatically, since ngx.req.set_uri_args() fills the
arguments in a non-stable, essentially random order into ngx.var.args,
even for multiple, sequential requests that are identical.

As a workaround, we're simply using ngx.re.gsub(ngx.var.args, ...),
but the old solution is more elegant in my opinon. We've tried
multiple ways to re-sort the args table before passing it to
ngx.req.set_uri_args() without any observable change in behavior. Is
there any way to make ngx.req.set_uri_args() produce predictable
$ngs.var.args?

Rainer

--
Rainer Canavan

Junlong li

unread,
Jul 5, 2022, 10:11:47 AM7/5/22
to openresty-en
the luajit imports the randomness for security reasons.
So the order of the elements in the table will change from time to time.

Reply all
Reply to author
Forward
0 new messages