aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-05 15:35:04 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-03-05 15:35:04 +0000
commit4e8e8e8b14d3550bb851baa1b601fa9626d80a45 (patch)
treec1bd89ddc1b921aad4f4e19c79ff793b69282682 /src/libutil
parentff5125a975f3a3c143c84aa9cf2f6878f5930272 (diff)
downloadrspamd-4e8e8e8b14d3550bb851baa1b601fa9626d80a45.tar.gz
rspamd-4e8e8e8b14d3550bb851baa1b601fa9626d80a45.zip
[Project] Check `Connection` header
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/http_context.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/libutil/http_context.c b/src/libutil/http_context.c
index da2481640..d8b576d1f 100644
--- a/src/libutil/http_context.c
+++ b/src/libutil/http_context.c
@@ -381,21 +381,26 @@ rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
g_assert (conn->keepalive_hash_key != NULL);
- /* Move connection to the keepalive pool */
- cbdata = g_malloc0 (sizeof (*cbdata));
+ if (msg) {
+ const rspamd_ftok_t *tok;
+ rspamd_ftok_t cmp;
- cbdata->conn = rspamd_http_connection_ref (conn);
- g_queue_push_tail (&conn->keepalive_hash_key->conns, cbdata);
- cbdata->link = conn->keepalive_hash_key->conns.tail;
- cbdata->queue = &conn->keepalive_hash_key->conns;
- conn->finished = FALSE;
+ tok = rspamd_http_message_find_header (msg, "Connection");
- event_set (&cbdata->ev, conn->fd, EV_READ|EV_TIMEOUT,
- rspamd_http_keepalive_handler,
- &cbdata);
+ if (!tok) {
+ /* Server has not stated that it can do keep alive */
+ conn->finished = TRUE;
+ return;
+ }
- if (msg) {
- const rspamd_ftok_t *tok;
+ RSPAMD_FTOK_ASSIGN (&cmp, "keep-alive");
+
+ if (rspamd_ftok_casecmp (&cmp, tok) != 0) {
+ conn->finished = TRUE;
+ return;
+ }
+
+ /* We can proceed, check timeout */
tok = rspamd_http_message_find_header (msg, "Keep-Alive");
@@ -412,7 +417,7 @@ rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
if (end_pos) {
if (rspamd_strtol (tok->begin + pos + 1,
(end_pos - tok->begin) - pos - 1, &real_timeout) &&
- real_timeout > 0) {
+ real_timeout > 0) {
timeout = real_timeout;
}
}
@@ -427,6 +432,19 @@ rspamd_http_context_push_keepalive (struct rspamd_http_context *ctx,
}
}
+ /* Move connection to the keepalive pool */
+ cbdata = g_malloc0 (sizeof (*cbdata));
+
+ cbdata->conn = rspamd_http_connection_ref (conn);
+ g_queue_push_tail (&conn->keepalive_hash_key->conns, cbdata);
+ cbdata->link = conn->keepalive_hash_key->conns.tail;
+ cbdata->queue = &conn->keepalive_hash_key->conns;
+ conn->finished = FALSE;
+
+ event_set (&cbdata->ev, conn->fd, EV_READ|EV_TIMEOUT,
+ rspamd_http_keepalive_handler,
+ &cbdata);
+
double_to_tv (timeout, &tv);
event_base_set (ev_base, &cbdata->ev);
event_add (&cbdata->ev, &tv);