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.
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 @@
"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 @@
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 @@
if (!http_update_authority(htx, sl, hdr_value))
goto error_htx;
}
+ if (isteqi(hdr->name, ist("connection")))
+ connection_hdr = 1;
}
}
@@ -1348,7 +1351,7 @@
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 @@
}
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;