[MEDIUM] make it possible to combine http-pretend-keepalived with httpclose
Some configs may involve httpclose in a frontend and http-pretend-keepalive
in a backend. httpclose used to take priority over keepalive, thus voiding
its effect. This change ensures that when both are combined, keepalive is
still announced to the server while close is announced to the client.
(cherry picked from commit 2be7ec90fa9caf66294f446423bbab2d00db9004)
diff --git a/doc/configuration.txt b/doc/configuration.txt
index e845546..926ce9a 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -2834,8 +2834,9 @@
This option may be set both in a frontend and in a backend. It is enabled if
at least one of the frontend or backend holding a connection has it enabled.
- This option has no effect if it is combined with "option httpclose", which
- has precedence.
+ This option may be compbined with "option httpclose", which will cause
+ keepalive to be announced to the server and close to be announced to the
+ client. This practice is discouraged though.
If this option has been enabled in a "defaults" section, it can be disabled
in a specific instance by prepending the "no" keyword before it.
diff --git a/src/proto_http.c b/src/proto_http.c
index 9d30ffc..4e4ac4d 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -3006,7 +3006,8 @@
(txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL) &&
((txn->flags & TX_HDR_CONN_CLO) || /* "connection: close" */
(txn->flags & (TX_REQ_VER_11|TX_HDR_CONN_KAL)) == 0 || /* no "connection: k-a" in 1.0 */
- ((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE) || /* httpclose + any = forceclose */
+ (((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE) && /* httpclose without pretend-ka... */
+ 1/*!((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)*/) || /* ... +any = forceclose */
!(txn->flags & TX_REQ_XFER_LEN) || /* no length known => close */
s->fe->state == PR_STSTOPPED)) /* frontend is stopping */
txn->flags = (txn->flags & ~TX_CON_WANT_MSK) | TX_CON_WANT_CLO;
@@ -3433,18 +3434,19 @@
/* 11: add "Connection: close" or "Connection: keep-alive" if needed and not yet set. */
if (((txn->flags & TX_CON_WANT_MSK) != TX_CON_WANT_TUN) ||
- ((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE)) {
+ ((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE) ||
+ ((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)) {
unsigned int want_flags = 0;
if (txn->flags & TX_REQ_VER_11) {
- if (((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL &&
- !((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA)) ||
- ((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE))
+ if (((txn->flags & TX_CON_WANT_MSK) >= TX_CON_WANT_SCL ||
+ ((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE)) &&
+ !((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
want_flags |= TX_CON_CLO_SET;
} else {
- if ((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL ||
- (((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA) &&
- !((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE)))
+ if (((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL &&
+ !((s->fe->options|s->be->options) & PR_O_HTTP_CLOSE)) ||
+ ((s->fe->options2|s->be->options2) & PR_O2_FAKE_KA))
want_flags |= TX_CON_KAL_SET;
}