MAJOR: proxy/htx: Handle mux upgrades from TCP to HTTP in HTX mode

It is now possible to upgrade TCP streams to HTX when an HTTP backend is set for
a TCP frontend (both with the HTX enabled). So concretely, in such case, an
upgrade is performed from the mux pt to the mux h1. The current CS and the
channel's buffer are used to initialize the mux h1.
diff --git a/src/proxy.c b/src/proxy.c
index 8c4b2f2..276fc42 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -1325,7 +1325,7 @@
 	proxy_inc_be_ctr(be);
 
 	/* HTX/legacy must match */
-	if ((s->sess->fe->options2 ^ be->options2) & PR_O2_USE_HTX)
+	if ((strm_fe(s)->options2 ^ be->options2) & PR_O2_USE_HTX)
 		return 0;
 
 	/* assign new parameters to the stream from the new backend */
@@ -1371,6 +1371,20 @@
 		    ((strm_fe(s)->options & PR_O_HTTP_MODE) != (be->options & PR_O_HTTP_MODE)))
 			http_adjust_conn_mode(s, s->txn, &s->txn->req);
 
+		/* If we chain a TCP frontend to an HTX backend, we must upgrade
+		 * the client mux */
+		if (!IS_HTX_STRM(s) && be->mode == PR_MODE_HTTP && (be->options2 & PR_O2_USE_HTX)) {
+			struct connection  *conn = objt_conn(strm_sess(s)->origin);
+			struct conn_stream *cs   = objt_cs(s->si[0].end);
+
+			if (conn && cs) {
+				si_rx_endp_more(&s->si[0]);
+				if (conn_upgrade_mux_fe(conn, cs, &s->req.buf, ist(""), PROTO_MODE_HTX)  == -1)
+					return 0;
+				s->flags |= SF_HTX;
+			}
+		}
+
 		/* If an LB algorithm needs to access some pre-parsed body contents,
 		 * we must not start to forward anything until the connection is
 		 * confirmed otherwise we'll lose the pointer to these data and