aboutsummaryrefslogtreecommitdiffstats
path: root/src/lua/lua_http.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-12-09 14:02:18 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-12-09 14:02:18 +0000
commit05d6d354ec99e800007828137315b42be332c719 (patch)
tree4f357f0795a28202e0e5703506dc1d9069deafa9 /src/lua/lua_http.c
parent4fe64bdcb51eb13b732bfcab0ffb321b16e91395 (diff)
downloadrspamd-05d6d354ec99e800007828137315b42be332c719.tar.gz
rspamd-05d6d354ec99e800007828137315b42be332c719.zip
[Feature] Allow to skip DNS resolution for keep-alive connections
Diffstat (limited to 'src/lua/lua_http.c')
-rw-r--r--src/lua/lua_http.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index 1fee9e313..85aa04e1f 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -389,6 +389,7 @@ lua_http_make_connection (struct lua_http_cbdata *cbd)
{
rspamd_inet_address_set_port (cbd->addr, cbd->msg->port);
unsigned http_opts = RSPAMD_HTTP_CLIENT_SIMPLE;
+ struct rspamd_http_message *msg = cbd->msg;
if (cbd->msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL) {
http_opts |= RSPAMD_HTTP_CLIENT_SSL;
@@ -1036,20 +1037,6 @@ lua_http_request (lua_State *L)
}
- const rspamd_ftok_t *host_header_tok = rspamd_http_message_find_header (msg, "Host");
- if (host_header_tok != NULL) {
- if (msg->host) {
- g_string_free (msg->host, true);
- }
- msg->host = g_string_new_len (host_header_tok->begin, host_header_tok->len);
- cbd->host = msg->host->str;
- }
- else {
- if (msg->host) {
- cbd->host = msg->host->str;
- }
- }
-
if (body) {
if (gzip) {
if (rspamd_fstring_gzip (&body)) {
@@ -1064,8 +1051,31 @@ lua_http_request (lua_State *L)
cbd->session = session;
}
- if (msg->host && rspamd_parse_inet_address (&cbd->addr,
- msg->host->str, msg->host->len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
+ bool numeric_ip = false;
+
+ /* Check if we can skip resolving */
+ if (msg->host) {
+ cbd->host = msg->host->str;
+
+ if (cbd->flags & RSPAMD_LUA_HTTP_FLAG_KEEP_ALIVE) {
+ const rspamd_inet_addr_t *ka_addr = rspamd_http_context_has_keepalive(NULL,
+ msg->host->str, msg->port, msg->flags & RSPAMD_HTTP_FLAG_WANT_SSL);
+
+ if (ka_addr) {
+ cbd->addr = rspamd_inet_address_copy(ka_addr);
+ numeric_ip = true;
+ }
+ }
+
+ if (!cbd->addr) {
+ if (rspamd_parse_inet_address (&cbd->addr,
+ msg->host->str, msg->host->len, RSPAMD_INET_ADDRESS_PARSE_DEFAULT)) {
+ numeric_ip = true;
+ }
+ }
+ }
+
+ if (numeric_ip) {
/* Host is numeric IP, no need to resolve */
gboolean ret;