Skip to content

Commit

Permalink
[Minor] Improve options
Browse files Browse the repository at this point in the history
  • Loading branch information
vstakhov committed Apr 22, 2023
1 parent a8a5805 commit 5892a97
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/plugins/lua/url_redirector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ local function cache_url(task, orig_url, url, key, prefix)
end
end

-- Reduce length of a string to a given length (16 by default)
local function maybe_trim_url(url, limit)
if not limit then limit = 16 end
if #url > limit then
return string.sub(url, 1, limit) .. '...'
else
return url
end
end

-- Resolve maybe cached url
-- Orig url is the original url object
-- url should be a new url object...
Expand All @@ -171,7 +181,8 @@ local function resolve_cached(task, orig_url, url, key, ntries)
rspamd_logger.debugm(N, task, 'cannot get more requests to resolve %s, stop on %s after %s attempts',
orig_url, url, ntries)
cache_url(task, orig_url, url, key, 'nested')
task:insert_result(settings.redirector_symbol_nested, 1.0, tostring(ntries))
task:insert_result(settings.redirector_symbol_nested, 1.0,
string.format('%s->%s:%d', maybe_trim_url(orig_url), maybe_trim_url(url), ntries))

return
end
Expand Down Expand Up @@ -268,7 +279,8 @@ local function resolve_cached(task, orig_url, url, key, ntries)
-- Prefixed url stored
local prefix, new_url = data:match('^%^(%a+):(.+)$')
if prefix == 'nested' then
task:insert_result(settings.redirector_symbol_nested, 1.0, 'cached')
task:insert_result(settings.redirector_symbol_nested, 1.0,
string.format('%s->%s:cached', maybe_trim_url(url), maybe_trim_url(new_url)))
end
data = new_url
end
Expand Down

0 comments on commit 5892a97

Please sign in to comment.