From 4b5f3029bcd36af5f4da8a3d85cc944d37a87769 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 5 Sep 2022 09:05:17 +0200 Subject: [PATCH] MINOR: http-check: Remove support for headers/body in "option httpchk" version This trick is deprecated since the health-check refactoring, It is now invalid. It means the following line will trigger an error during the configuration parsing: option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www It must be replaced by: option httpchk OPTIONS * HTTP/1.1 http-check send hdr Host www --- doc/configuration.txt | 5 -- ...4be_1srv_smtpchk_httpchk_layer47errors.vtc | 3 +- reg-tests/checks/http-check-send.vtc | 5 +- reg-tests/checks/tls_health_checks.vtc | 6 +- src/tcpcheck.c | 62 +------------------ 5 files changed, 10 insertions(+), 71 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 8e95b0bf7..f1fc0bbff 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -9247,11 +9247,6 @@ option httpchk internally relies on an HTX multiplexer. Thus, it means the request formatting and the response parsing will be strict. - Note : For a while, there was no way to add headers or body in the request - used for HTTP health checks. So a workaround was to hide it at the end - of the version string with a "\r\n" after the version. It is now - deprecated. The directive "http-check send" must be used instead. - Examples : # Relay HTTPS traffic to Apache instance and check service availability # using HTTP request "OPTIONS * HTTP/1.1" on port 80. diff --git a/reg-tests/checks/4be_1srv_smtpchk_httpchk_layer47errors.vtc b/reg-tests/checks/4be_1srv_smtpchk_httpchk_layer47errors.vtc index 5286bdb8d..2e98a3f89 100644 --- a/reg-tests/checks/4be_1srv_smtpchk_httpchk_layer47errors.vtc +++ b/reg-tests/checks/4be_1srv_smtpchk_httpchk_layer47errors.vtc @@ -65,7 +65,8 @@ haproxy h1 -conf { backend be2 mode tcp log ${S2_addr}:${S2_port} daemon - option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www + option httpchk OPTIONS * HTTP/1.1 + http-check send hdr Host www server srv2 ${s2_addr}:${s2_port} check backend be3 diff --git a/reg-tests/checks/http-check-send.vtc b/reg-tests/checks/http-check-send.vtc index 0970ee47f..530ad7566 100644 --- a/reg-tests/checks/http-check-send.vtc +++ b/reg-tests/checks/http-check-send.vtc @@ -28,7 +28,6 @@ server s3 { expect req.method == OPTIONS expect req.url == / expect req.proto == HTTP/1.0 - expect req.http.hdr == expect req.http.host == expect req.http.x-test == expect req.bodylen == 0 @@ -41,7 +40,6 @@ server s4 { expect req.url == /status expect req.proto == HTTP/1.1 expect req.http.connection == "close" - expect req.http.hdr == expect req.http.host == "my-www-host" expect req.http.x-test == true expect req.http.content-length == 4 @@ -55,7 +53,6 @@ server s5 { expect req.method == OPTIONS expect req.url == / expect req.proto == HTTP/1.0 - expect req.http.hdr == expect req.http.host == "other-www-host" expect req.http.x-test == expect req.http.x-new-test == true @@ -134,7 +131,7 @@ haproxy h1 -conf { timeout client "${HAPROXY_TEST_TIMEOUT-5s}" timeout server "${HAPROXY_TEST_TIMEOUT-5s}" timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" - option httpchk GET /status HTTP/1.1\r\nHdr:\ must-be-removed + option httpchk GET /status HTTP/1.1 option log-health-checks http-check send hdr Host "my-www-host" hdr X-test true body "test" diff --git a/reg-tests/checks/tls_health_checks.vtc b/reg-tests/checks/tls_health_checks.vtc index 1989d6508..9c268f485 100644 --- a/reg-tests/checks/tls_health_checks.vtc +++ b/reg-tests/checks/tls_health_checks.vtc @@ -95,7 +95,8 @@ haproxy h2 -conf { backend be2 option log-health-checks - option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www + option httpchk OPTIONS * HTTP/1.1 + http-check send hdr Host www log ${S2_addr}:${S2_port} daemon server srv1 ${h1_fe1_addr}:${h1_fe1_port} ssl crt ${testdir}/common.pem verify none check @@ -106,7 +107,8 @@ haproxy h2 -conf { backend be6 option log-health-checks - option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www + option httpchk OPTIONS * HTTP/1.1 + http-check send hdr Host www log ${S6_addr}:${S6_port} daemon server srv3 127.0.0.1:80 crt ${testdir}/common.pem verify none check check-ssl port ${h1_fe3_port} addr ${h1_fe3_addr}:80 } -start diff --git a/src/tcpcheck.c b/src/tcpcheck.c index e597cf825..fc5197d5a 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -4915,19 +4915,10 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s hdrs = (*args[cur_arg+2] ? strstr(args[cur_arg+2], "\r\n") : NULL); body = (*args[cur_arg+2] ? strstr(args[cur_arg+2], "\r\n\r\n") : NULL); - if (hdrs == body) - hdrs = NULL; - if (hdrs) { - *hdrs = '\0'; - hdrs +=2; - } - if (body) { - *body = '\0'; - body += 4; - } if (hdrs || body) { - memprintf(errmsg, "hiding headers or body at the end of the version string is deprecated." - " Please, consider to use 'http-check send' directive instead."); + memprintf(errmsg, "hiding headers or body at the end of the version string is unsupported." + "Use 'http-check send' directive instead."); + goto error; } chk = calloc(1, sizeof(*chk)); @@ -4977,53 +4968,6 @@ static struct tcpcheck_rule *proxy_parse_httpchk_req(char **args, int cur_arg, s } } - /* Copy the header */ - if (hdrs) { - struct http_hdr tmp_hdrs[global.tune.max_http_hdr]; - struct h1m h1m; - int i, ret; - - /* Build and parse the request */ - chunk_printf(&trash, "%s\r\n\r\n", hdrs); - - h1m.flags = H1_MF_HDRS_ONLY; - ret = h1_headers_to_hdr_list(b_orig(&trash), b_tail(&trash), - tmp_hdrs, sizeof(tmp_hdrs)/sizeof(tmp_hdrs[0]), - &h1m, NULL); - if (ret <= 0) { - memprintf(errmsg, "unable to parse the request '%s'.", b_orig(&trash)); - goto error; - } - - for (i = 0; istlen(tmp_hdrs[i].n); i++) { - hdr = calloc(1, sizeof(*hdr)); - if (!hdr) { - memprintf(errmsg, "out of memory"); - goto error; - } - LIST_INIT(&hdr->value); - hdr->name = istdup(tmp_hdrs[i].n); - if (!isttest(hdr->name)) { - memprintf(errmsg, "out of memory"); - goto error; - } - - ist0(tmp_hdrs[i].v); - if (!parse_logformat_string(istptr(tmp_hdrs[i].v), px, &hdr->value, 0, SMP_VAL_BE_CHK_RUL, errmsg)) - goto error; - LIST_APPEND(&chk->send.http.hdrs, &hdr->list); - } - } - - /* Copy the body */ - if (body) { - chk->send.http.body = ist(strdup(body)); - if (!isttest(chk->send.http.body)) { - memprintf(errmsg, "out of memory"); - goto error; - } - } - return chk; error: