]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-check: Remove support for headers/body in "option httpchk" version
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 5 Sep 2022 07:05:17 +0000 (09:05 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 6 Sep 2022 16:23:14 +0000 (18:23 +0200)
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
reg-tests/checks/4be_1srv_smtpchk_httpchk_layer47errors.vtc
reg-tests/checks/http-check-send.vtc
reg-tests/checks/tls_health_checks.vtc
src/tcpcheck.c

index 8e95b0bf7f3946dc51a9a56f8e4c11c15a029921..f1fc0bbff561438cd1d4bcf4eaf6d1e4003c248d 100644 (file)
@@ -9247,11 +9247,6 @@ option httpchk <method> <uri> <version>
   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.
index 5286bdb8d46f679dddbad67eae39131638398906..2e98a3f89a5e011b85096ff2cb544c43ec937170 100644 (file)
@@ -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
index 0970ee47fe8f181d58422c61787e79bd311feb20..530ad75669e20584f452d497e9aa7b8d72758683 100644 (file)
@@ -28,7 +28,6 @@ server s3 {
     expect req.method == OPTIONS
     expect req.url == /
     expect req.proto == HTTP/1.0
-    expect req.http.hdr == <undef>
     expect req.http.host == <undef>
     expect req.http.x-test == <undef>
     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 == <undef>
     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 == <undef>
     expect req.http.host == "other-www-host"
     expect req.http.x-test == <undef>
     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"
 
index 1989d6508b8583cfd004c828e080e3319583ab22..9c268f4858d1f7b17bb2a3305f01e07391b5159d 100644 (file)
@@ -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
index e597cf825fd6defcd9657790537e388d1f17d3c0..fc5197d5a96fda4b444eb8c4b9afd66ded086f4e 100644 (file)
@@ -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: