]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: check: do not ignore a connection header for http-check send
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 22 Dec 2020 13:08:52 +0000 (14:08 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 22 Dec 2020 13:22:44 +0000 (14:22 +0100)
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
src/tcpcheck.c

index 3e9e62a62f635adc91bc5d55e324b9e3193a4587..95b020c03f94afb2231c58fb04082f48b1f080f4 100644 (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
index 9d3b411e518b3e494899c8c270b11d1b046fa151..0570b811b133ae01fcf86216963ac5c222cc2cbd 100644 (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;