BUG/MINOR: h1-htx: Remove flags about protocol upgrade on non-101 responses

It is possible to have an "upgrade:" header and the corresponding value in
the "connection:" header for a non-101 response. It happens for
426-Upgrade-Required messages. However, on HAProxy side, a parsing error is
reported for this kind of message because no websocket key header
("sec-websocket-accept:") is found in the response.

So a possible fix could be to not perform this test for non-101
responses. However, having flags about protocol upgrade on this kind of
response could lead to other bugs. Instead, corresponding flags are
removed. Thus, during the H1 response post-parsing, H1_MF_CONN_UPG and
H1_MF_UPG_WEBSOCKET flags are removed from any non-101 response.

This patch should fix the issue #1997. It must be backported as far as 2.4.

(cherry picked from commit 5f36bfe42e6fe1daa764c38a8ba158b710e52530)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit b4784965cbcc2b914477a8a47be52cbf6803b62d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 48bb2f41aa7d553f8efb66309e3cbe2234b0a2c9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 45802865fe7a308894d9b85a6f20578aed80a477)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/h1_htx.c b/src/h1_htx.c
index b6a91f2..650acba 100644
--- a/src/h1_htx.c
+++ b/src/h1_htx.c
@@ -279,6 +279,9 @@
 		goto output_full;
 	}
 
+	if ((h1m->flags & (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET)) && code != 101)
+		h1m->flags &= ~(H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET);
+
 	if (((h1m->flags & H1_MF_METH_CONNECT) && code >= 200 && code < 300) || code == 101) {
 		h1m->flags &= ~(H1_MF_CLEN|H1_MF_CHNK);
 		h1m->flags |= H1_MF_XFER_LEN;