From 4c8e58def6042081af4a721db8d53ca91b335a38 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 5 Jul 2022 15:33:53 +0200 Subject: [PATCH] BUG/MINOR: http-check: Preserve headers if not redefined by an implicit rule When an explicit "http-check send" rule is used, if it is the first one, it is merge with the implicit rule created by "option httpchk" statement. The opposite is also true. Idea is to have only one send rule with the merged info. It means info defined in the second rule override those defined in the first one. However, if an element is not defined in the second rule, it must be ignored, keeping this way info from the first rule. It works as expected for the method, the uri and the request version. But it is not true for the header list. For instance, with the following statements, a x-forwarded-proto header is added to healthcheck requests: option httpchk http-check send meth GET hdr x-forwarded-proto https while by inverting the statements, no extra headers are added: http-check send meth GET hdr x-forwarded-proto https option httpchk Now the old header list is overriden if the new one is not empty. This patch should fix the issue #1772. It must be backported as far as 2.2. --- src/tcpcheck.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 1c6d083c8..f254c80fc 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -3534,10 +3534,12 @@ void tcpcheck_overwrite_send_http_rule(struct tcpcheck_rule *old, struct tcpchec new->send.http.vsn = IST_NULL; } - free_tcpcheck_http_hdrs(&old->send.http.hdrs); - list_for_each_entry_safe(hdr, bhdr, &new->send.http.hdrs, list) { - LIST_DELETE(&hdr->list); - LIST_APPEND(&old->send.http.hdrs, &hdr->list); + if (!LIST_ISEMPTY(&new->send.http.hdrs)) { + free_tcpcheck_http_hdrs(&old->send.http.hdrs); + list_for_each_entry_safe(hdr, bhdr, &new->send.http.hdrs, list) { + LIST_DELETE(&hdr->list); + LIST_APPEND(&old->send.http.hdrs, &hdr->list); + } } if (!(new->send.http.flags & TCPCHK_SND_HTTP_FL_BODY_FMT) && isttest(new->send.http.body)) {