]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
reuse http_request data
authorDmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
Mon, 14 Oct 2024 14:01:35 +0000 (16:01 +0200)
committerDmitriy Alekseev <1865999+dragoangel@users.noreply.github.com>
Mon, 14 Oct 2024 14:01:35 +0000 (16:01 +0200)
src/plugins/lua/elastic.lua

index 368ef5b746706bad4dc1e02eb1988c72bce5d1b8..45c5c2edf3a9fb6f87feaaef8a9c0ad1d233c2ff 100644 (file)
@@ -409,44 +409,29 @@ local function elastic_send_data(flush_all, task, cfg, ev_base)
   end
 
   if nlogs_to_send > 0 then
+    local http_request = {
+      url = push_url,
+      headers = {
+        ['Host'] = host,
+        ['Content-Type'] = 'application/x-ndjson',
+      },
+      body = bulk_json,
+      method = 'post',
+      callback=http_callback,
+      gzip = settings.use_gzip,
+      keepalive = settings.use_keepalive,
+      no_ssl_verify = settings.no_ssl_verify,
+      user = settings.user,
+      password = settings.password,
+      timeout = settings.timeout,
+    }
     if task then
-      return rspamd_http.request({
-        url = push_url,
-        headers = {
-          ['Host'] = host,
-          ['Content-Type'] = 'application/x-ndjson',
-        },
-        body = bulk_json,
-        task = task,
-        method = 'post',
-        callback=http_callback,
-        gzip = settings.use_gzip,
-        keepalive = settings.use_keepalive,
-        no_ssl_verify = settings.no_ssl_verify,
-        user = settings.user,
-        password = settings.password,
-        timeout = settings.timeout,
-      })
+      http_request['task'] = task
     else
-      return rspamd_http.request({
-        url = push_url,
-        headers = {
-          ['Host'] = host,
-          ['Content-Type'] = 'application/x-ndjson',
-        },
-        body = bulk_json,
-        ev_base = ev_base,
-        config = cfg,
-        method = 'post',
-        callback=http_callback,
-        gzip = settings.use_gzip,
-        keepalive = settings.use_keepalive,
-        no_ssl_verify = settings.no_ssl_verify,
-        user = settings.user,
-        password = settings.password,
-        timeout = settings.timeout,
-      })
+      http_request['ev_base'] = ev_base
+      http_request['config'] = cfg
     end
+    return rspamd_http.request(http_request)
   end
 end