From 6d975f0af650e51c5c8e584d9b6beb413deb6868 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 22 Dec 2020 14:08:52 +0100 Subject: [PATCH] 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. --- doc/configuration.txt | 9 +++------ src/tcpcheck.c | 8 +++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 3e9e62a..95b020c 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -5411,14 +5411,11 @@ http-check send [meth ] [{ uri | uri-lf }>] [ver ] "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 diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 9d3b411..0570b81 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -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; -- 1.7.10.4