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
This commit is contained in:
Christopher Faulet 2022-09-05 09:05:17 +02:00
parent 6aec1f380e
commit 4b5f3029bc
5 changed files with 10 additions and 71 deletions

View File

@ -9247,11 +9247,6 @@ option httpchk <method> <uri> <version>
internally relies on an HTX multiplexer. Thus, it means the request internally relies on an HTX multiplexer. Thus, it means the request
formatting and the response parsing will be strict. 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 : Examples :
# Relay HTTPS traffic to Apache instance and check service availability # Relay HTTPS traffic to Apache instance and check service availability
# using HTTP request "OPTIONS * HTTP/1.1" on port 80. # using HTTP request "OPTIONS * HTTP/1.1" on port 80.

View File

@ -65,7 +65,8 @@ haproxy h1 -conf {
backend be2 backend be2
mode tcp mode tcp
log ${S2_addr}:${S2_port} daemon 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 server srv2 ${s2_addr}:${s2_port} check
backend be3 backend be3

View File

@ -28,7 +28,6 @@ server s3 {
expect req.method == OPTIONS expect req.method == OPTIONS
expect req.url == / expect req.url == /
expect req.proto == HTTP/1.0 expect req.proto == HTTP/1.0
expect req.http.hdr == <undef>
expect req.http.host == <undef> expect req.http.host == <undef>
expect req.http.x-test == <undef> expect req.http.x-test == <undef>
expect req.bodylen == 0 expect req.bodylen == 0
@ -41,7 +40,6 @@ server s4 {
expect req.url == /status expect req.url == /status
expect req.proto == HTTP/1.1 expect req.proto == HTTP/1.1
expect req.http.connection == "close" expect req.http.connection == "close"
expect req.http.hdr == <undef>
expect req.http.host == "my-www-host" expect req.http.host == "my-www-host"
expect req.http.x-test == true expect req.http.x-test == true
expect req.http.content-length == 4 expect req.http.content-length == 4
@ -55,7 +53,6 @@ server s5 {
expect req.method == OPTIONS expect req.method == OPTIONS
expect req.url == / expect req.url == /
expect req.proto == HTTP/1.0 expect req.proto == HTTP/1.0
expect req.http.hdr == <undef>
expect req.http.host == "other-www-host" expect req.http.host == "other-www-host"
expect req.http.x-test == <undef> expect req.http.x-test == <undef>
expect req.http.x-new-test == true expect req.http.x-new-test == true
@ -134,7 +131,7 @@ haproxy h1 -conf {
timeout client "${HAPROXY_TEST_TIMEOUT-5s}" timeout client "${HAPROXY_TEST_TIMEOUT-5s}"
timeout server "${HAPROXY_TEST_TIMEOUT-5s}" timeout server "${HAPROXY_TEST_TIMEOUT-5s}"
timeout connect "${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 option log-health-checks
http-check send hdr Host "my-www-host" hdr X-test true body "test" http-check send hdr Host "my-www-host" hdr X-test true body "test"

View File

@ -95,7 +95,8 @@ haproxy h2 -conf {
backend be2 backend be2
option log-health-checks 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 log ${S2_addr}:${S2_port} daemon
server srv1 ${h1_fe1_addr}:${h1_fe1_port} ssl crt ${testdir}/common.pem verify none check 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 backend be6
option log-health-checks 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 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 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 } -start

View 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); 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); 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) { if (hdrs || body) {
memprintf(errmsg, "hiding headers or body at the end of the version string is deprecated." memprintf(errmsg, "hiding headers or body at the end of the version string is unsupported."
" Please, consider to use 'http-check send' directive instead."); "Use 'http-check send' directive instead.");
goto error;
} }
chk = calloc(1, sizeof(*chk)); 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; return chk;
error: error: