]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-rules: Handle the rule direction when a redirect is evaluated
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 28 Jan 2020 08:18:10 +0000 (09:18 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Feb 2020 13:55:34 +0000 (14:55 +0100)
The rule direction must be tested to do specific processing on the request
path. intercepted_req counter shoud be updated if the rule is evaluated on the
frontend and remaining request's analyzers must be removed. But only on the
request path. The rule direction must also be tested to set the right final
stream state flag.

This patch depends on the commit "MINOR: http-rules: Add a flag on redirect
rules to know the rule direction". Both must be backported to all stable
versions.

src/http_ana.c

index a7e8abf7bb25325debcc159ce1dfddc16107d9ef..eb260056da934631361f927c4244148fb07533e2 100644 (file)
@@ -2663,9 +2663,6 @@ int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struc
 
        htx_to_buf(htx, &res->buf);
 
-       /* let's log the request time */
-       s->logs.tv_request = now;
-
        htx->flags |= HTX_FL_PROXY_RESP;
        data = htx->data - co_data(res);
        c_adv(res, data);
@@ -2681,13 +2678,19 @@ int http_apply_redirect_rule(struct redirect_rule *rule, struct stream *s, struc
        channel_auto_read(res);
        channel_auto_close(res);
        channel_shutr_now(res);
+       if (rule->flags & REDIRECT_FLAG_FROM_REQ) {
+               /* let's log the request time */
+               s->logs.tv_request = now;
+               req->analysers &= AN_REQ_FLT_END;
 
-       req->analysers &= AN_REQ_FLT_END;
+               if (s->sess->fe == s->be) /* report it if the request was intercepted by the frontend */
+                       _HA_ATOMIC_ADD(&s->sess->fe->fe_counters.intercepted_req, 1);
+       }
 
        if (!(s->flags & SF_ERR_MASK))
                s->flags |= SF_ERR_LOCAL;
        if (!(s->flags & SF_FINST_MASK))
-               s->flags |= SF_FINST_R;
+               s->flags |= ((rule->flags & REDIRECT_FLAG_FROM_REQ) ? SF_FINST_R : SF_FINST_H);
 
        free_trash_chunk(chunk);
        return 1;