From bbe685452fa328fe35ff7c430b228ec2614c9732 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 8 Apr 2019 10:53:51 +0200 Subject: [PATCH] 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. --- src/proxy.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/proxy.c b/src/proxy.c index 8c4b2f26f..276fc425b 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -1325,7 +1325,7 @@ int stream_set_backend(struct stream *s, struct proxy *be) 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 @@ int stream_set_backend(struct stream *s, struct proxy *be) ((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