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.
This commit is contained in:
Christopher Faulet 2022-07-05 15:33:53 +02:00
parent f0196f4f71
commit 4c8e58def6

View File

@ -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)) {