MINOR: check: do not ignore a connection header for http-check send

Allow the user to specify a custom Connection header for http-check
send. This is useful for example to implement a websocket upgrade check.

If no connection header has been set, a 'Connection: close' header is
automatically appended to allow the server to close the connection
immediately after the request/response.

Update the documentation related to http-check send.

This fixes the github issue #1009.
This commit is contained in:
Amaury Denoyelle 2020-12-22 14:08:52 +01:00 committed by Willy Tarreau
parent 4f59d38616
commit 6d975f0af6
2 changed files with 8 additions and 9 deletions

View File

@ -5411,14 +5411,11 @@ http-check send [meth <method>] [{ uri <uri> | uri-lf <fmt> }>] [ver <version>]
"Transfer-encoding" header should not be present in the request provided by
"http-check send". If so, it will be ignored. The old trick consisting to add
headers after the version string on the "option httpchk" line is now
deprecated. Note also the "Connection: close" header is still added if a
"http-check expect" directive is defined independently of this directive, just
like the state header if the directive "http-check send-state" is defined.
deprecated.
Also "http-check send" doesn't support HTTP keep-alive. Keep in mind that it
will automatically append a "Connection: close" header, meaning that this
header should not be present in the request provided by "http-check send". If
so, it will be ignored.
will automatically append a "Connection: close" header, unless a Connection
header has already already been configured via a hdr entry.
Note that the Host header and the request authority, when both defined, are
automatically synchronized. It means when the HTTP request is sent, when a

View File

@ -1225,6 +1225,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcpcheck_r
struct connection *conn = cs_conn(cs);
struct buffer *tmp = NULL;
struct htx *htx = NULL;
int connection_hdr = 0;
if (check->state & CHK_ST_OUT_ALLOC) {
ret = TCPCHK_EVAL_WAIT;
@ -1328,6 +1329,8 @@ enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcpcheck_r
if (!http_update_authority(htx, sl, hdr_value))
goto error_htx;
}
if (isteqi(hdr->name, ist("connection")))
connection_hdr = 1;
}
}
@ -1348,7 +1351,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_send(struct check *check, struct tcpcheck_r
body = send->http.body;
clen = ist((!istlen(body) ? "0" : ultoa(istlen(body))));
if (!htx_add_header(htx, ist("Connection"), ist("close")) ||
if ((!connection_hdr && !htx_add_header(htx, ist("Connection"), ist("close"))) ||
!htx_add_header(htx, ist("Content-length"), clen))
goto error_htx;
@ -2531,8 +2534,7 @@ struct tcpcheck_rule *parse_tcpcheck_send_http(char **args, int cur_arg, struct
}
host_hdr = i;
}
else if (strcasecmp(args[cur_arg+1], "connection") == 0 ||
strcasecmp(args[cur_arg+1], "content-length") == 0 ||
else if (strcasecmp(args[cur_arg+1], "content-length") == 0 ||
strcasecmp(args[cur_arg+1], "transfer-encoding") == 0)
goto skip_hdr;