commit 5892a97: [Minor] Improve options

Vsevolod Stakhov vsevolod at rspamd.com
Sat Apr 22 12:07:04 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-04-22 13:03:12 +0100
URL: https://github.com/rspamd/rspamd/commit/5892a97db26b2e0d58740fbe5ce7d16af57c0dc2 (HEAD -> master)

[Minor] Improve options

---
 src/plugins/lua/url_redirector.lua | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/plugins/lua/url_redirector.lua b/src/plugins/lua/url_redirector.lua
index ebe6c6ef6..c5748647d 100644
--- a/src/plugins/lua/url_redirector.lua
+++ b/src/plugins/lua/url_redirector.lua
@@ -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...
@@ -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
@@ -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


More information about the Commits mailing list