MINOR: http-rules: Handle the rule direction when a redirect is evaluated
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.
(cherry picked from commit 60b33a5a625cdc8e956d4f43aca5ab795240be33)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
[Cf: Thes BUG label is missing for this patch. It is the bug mentionned by the
commit "MINOR: http-rules: Add a flag on redirect rules to know the rule
direction".]
(cherry picked from commit 8956a7615149852fc4fa7f49536a657c198aced7)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
[Cf: Legacy HTTP code was also patched the same way ]
diff --git a/src/proto_http.c b/src/proto_http.c
index 6b5b558..237eb26 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -2447,8 +2447,6 @@
/* add end of headers and the keep-alive/close status. */
txn->status = rule->code;
- /* let's log the request time */
- s->logs.tv_request = now;
if (((!(req->flags & HTTP_MSGF_TE_CHNK) && !req->body_len) || (req->msg_state == HTTP_MSG_DONE)) &&
((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL ||
@@ -2483,6 +2481,11 @@
/* let the server side turn to SI_ST_CLO */
channel_shutw_now(req->chn);
channel_dont_connect(req->chn);
+
+ if (rule->flags & REDIRECT_FLAG_FROM_REQ) {
+ /* let's log the request time */
+ s->logs.tv_request = now;
+ }
} else {
/* keep-alive not possible */
if (unlikely(txn->flags & TX_USE_PX_CONN)) {
@@ -2495,13 +2498,21 @@
chunk->data += 23;
}
http_reply_and_close(s, txn->status, chunk);
- req->chn->analysers &= AN_REQ_FLT_END;
+
+ if (rule->flags & REDIRECT_FLAG_FROM_REQ) {
+ /* let's log the request time */
+ s->logs.tv_request = now;
+ req->chn->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);
ret = 1;
leave:
diff --git a/src/proto_htx.c b/src/proto_htx.c
index 2a4c654..e960cf1 100644
--- a/src/proto_htx.c
+++ b/src/proto_htx.c
@@ -2605,9 +2605,6 @@
htx_to_buf(htx, &res->buf);
- /* let's log the request time */
- s->logs.tv_request = now;
-
data = htx->data - co_data(res);
c_adv(res, data);
res->total += data;
@@ -2621,13 +2618,19 @@
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;