option httpchk <uri>
option httpchk <method> <uri>
option httpchk <method> <uri> <version>
+option httpchk <method> <uri> <version> <host>
Enables HTTP protocol to check on the servers health
May be used in the following contexts: tcp, http
<version> is the optional HTTP version string. It defaults to "HTTP/1.0"
but some servers might behave incorrectly in HTTP 1.0, so turning
it to HTTP/1.1 may sometimes help. Note that the Host field is
- mandatory in HTTP/1.1, use "http-check send" directive to add it.
+ mandatory in HTTP/1.1.
+
+ <host> is the optional HTTP Host header value. It is not set by default.
+ It is a log-format string.
By default, server health checks only consist in trying to establish a TCP
connection. When "option httpchk" is specified, a complete HTTP request is
expect req.method == OPTIONS
expect req.url == /
expect req.proto == HTTP/1.0
+ expect req.http.host == <undef>
txresp
} -start
expect req.method == GET
expect req.url == /status
expect req.proto == HTTP/1.1
+ expect req.http.host == "www.haproxy.org"
txresp
} -start
backend be2
log ${S1_addr}:${S1_port} len 2048 local0
- option httpchk GET /status HTTP/1.1
+ option httpchk GET /status HTTP/1.1 www.haproxy.org
server srv ${s2_addr}:${s2_port} check inter 100ms rise 1 fall 1
backend be3
{
struct tcpcheck_rule *chk = NULL;
struct tcpcheck_http_hdr *hdr = NULL;
- char *meth = NULL, *uri = NULL, *vsn = NULL;
+ char *meth = NULL, *uri = NULL, *vsn = NULL, *host = NULL;
char *hdrs, *body;
hdrs = (*args[cur_arg+2] ? strstr(args[cur_arg+2], "\r\n") : NULL);
uri = args[cur_arg+1];
if (*args[cur_arg+2])
vsn = args[cur_arg+2];
+ if (*args[cur_arg+3])
+ host = args[cur_arg+3];
if (meth) {
chk->send.http.meth.meth = find_http_meth(meth, strlen(meth));
goto error;
}
}
+ if (host) {
+ hdr = calloc(1, sizeof(*hdr));
+ if (!hdr) {
+ memprintf(errmsg, "out of memory");
+ goto error;
+ }
+ lf_expr_init(&hdr->value);
+ hdr->name = istdup(ist("host"));
+ if (!isttest(hdr->name)) {
+ memprintf(errmsg, "out of memory");
+ goto error;
+ }
+
+ if (!parse_logformat_string(host, px, &hdr->value, 0, SMP_VAL_BE_CHK_RUL, errmsg))
+ goto error;
+ LIST_APPEND(&chk->send.http.hdrs, &hdr->list);
+ hdr = NULL;
+ }
return chk;
if (warnifnotcap(curpx, PR_CAP_BE, file, line, args[cur_arg+1], NULL))
err_code |= ERR_WARN;
- if (alertif_too_many_args_idx(3, 1, file, line, args, &err_code))
+ if (alertif_too_many_args_idx(4, 1, file, line, args, &err_code))
goto out;
chk = proxy_parse_httpchk_req(args, cur_arg+2, curpx, &errmsg);