]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream: Use stream type instead of proxy mode when appropriate
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 8 Mar 2021 16:57:53 +0000 (17:57 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 1 Apr 2021 09:06:48 +0000 (11:06 +0200)
We now use the stream instead of the proxy to know if we are processing HTTP
data or not. If the stream is an HTX stream, it means we are dealing with
HTTP data. It is more accurate than the proxy mode because when an HTTP
upgrade is performed, the proxy is not changed and only the stream may be
used.

Note that it was not a problem to rely on the proxy because HTTP upgrades
may only happen when an HTTP backend was set. But, we will add the support
of HTTP upgrades on the frontend side, after te tcp-request rules
evaluation.  In this context, we cannot rely on the proxy mode.

src/backend.c
src/hlua.c
src/stream.c

index 96ff6569b259b9cc7b82cf2d5dd350fb31d21646..62be510e77feb439b3e659dfe8d0ac8e50303d5a 100644 (file)
@@ -1340,7 +1340,7 @@ int connect_server(struct stream *s)
        si_release_endpoint(&s->si[1]);
 
        /* do not reuse if mode is not http */
-       if (s->be->mode != PR_MODE_HTTP)
+       if (!IS_HTX_STRM(s))
                goto skip_reuse;
 
        /* first, search for a matching connection in the session's idle conns */
@@ -1576,7 +1576,7 @@ skip_reuse:
 #if defined(USE_OPENSSL) && defined(TLSEXT_TYPE_application_layer_protocol_negotiation)
                if (!srv ||
                    (srv->use_ssl != 1 || (!(srv->ssl_ctx.alpn_str) && !(srv->ssl_ctx.npn_str)) ||
-                    srv->mux_proto || s->be->mode != PR_MODE_HTTP))
+                    srv->mux_proto || !IS_HTX_STRM(s)))
 #endif
                        init_mux = 1;
 
@@ -1656,7 +1656,7 @@ skip_reuse:
                        conn_full_close(srv_conn);
                        return SF_ERR_INTERNAL;
                }
-               if (s->be->mode == PR_MODE_HTTP) {
+               if (IS_HTX_STRM(s)) {
                        /* If we're doing http-reuse always, and the connection
                         * is not private with available streams (an http2
                         * connection), add it to the available list, so that
index c162c84390f37c9b8f9520adafea14eebc1fc4b8..a61809e497ad51025ccb43f1f5cad5057bd89a52 100644 (file)
@@ -2952,7 +2952,7 @@ __LJMP static int hlua_channel_dup_yield(lua_State *L, int status, lua_KContext
 
        chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -2982,7 +2982,7 @@ __LJMP static int hlua_channel_get_yield(lua_State *L, int status, lua_KContext
 
        chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -3024,7 +3024,7 @@ __LJMP static int hlua_channel_getline_yield(lua_State *L, int status, lua_KCont
 
        chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -3074,7 +3074,7 @@ __LJMP static int hlua_channel_append_yield(lua_State *L, int status, lua_KConte
        int ret;
        int max;
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -3148,7 +3148,7 @@ __LJMP static int hlua_channel_set(lua_State *L)
        chn = MAY_LJMP(hlua_checkchannel(L, 1));
        lua_pushinteger(L, 0);
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -3179,7 +3179,7 @@ __LJMP static int hlua_channel_send_yield(lua_State *L, int status, lua_KContext
                return 1;
        }
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -3290,7 +3290,7 @@ __LJMP static int hlua_channel_forward_yield(lua_State *L, int status, lua_KCont
 
        chn = MAY_LJMP(hlua_checkchannel(L, 1));
 
-       if (chn_strm(chn)->be->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(chn_strm(chn))) {
                lua_pushfstring(L, "Cannot manipulate HAProxy channels in HTTP mode.");
                WILL_LJMP(lua_error(L));
        }
@@ -5505,7 +5505,7 @@ static int hlua_txn_new(lua_State *L, struct stream *s, struct proxy *p, int dir
 
        /* Creates the HTTP object is the current proxy allows http. */
        lua_pushstring(L, "http");
-       if (p->mode == PR_MODE_HTTP) {
+       if (IS_HTX_STRM(s)) {
                if (!hlua_http_new(L, htxn))
                        return 0;
        }
index 58fd5718e72353210872409925ecdd946ab86314..c1ba9050d9c90ea1d8cbeaff4349f50a8e9a1e29 100644 (file)
@@ -918,7 +918,7 @@ static void back_establish(struct stream *s)
        if (objt_server(s->target))
                health_adjust(objt_server(s->target), HANA_STATUS_L4_OK);
 
-       if (s->be->mode == PR_MODE_TCP) { /* let's allow immediate data connection in this case */
+       if (!IS_HTX_STRM(s)) { /* let's allow immediate data connection in this case */
                /* if the user wants to log as soon as possible, without counting
                 * bytes from the server, then this is the right moment. */
                if (!LIST_ISEMPTY(&strm_fe(s)->logformat) && !(s->logs.logwait & LW_BYTES)) {
@@ -935,7 +935,7 @@ static void back_establish(struct stream *s)
 
        /* Be sure to filter response headers if the backend is an HTTP proxy
         * and if there are filters attached to the stream. */
-       if (s->be->mode == PR_MODE_HTTP && HAS_FILTERS(s))
+       if (IS_HTX_STRM(s) && HAS_FILTERS(s))
                rep->analysers |= AN_RES_FLT_HTTP_HDRS;
 
        si_rx_endp_more(si);