]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: http_ana: split conditions for monitor-uri in wait for request
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 6 Jul 2021 09:23:10 +0000 (11:23 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 8 Jul 2021 15:11:17 +0000 (17:11 +0200)
Split in two the condition which check if the monitor-uri is set for the
current request. This will allow to easily use the http_uri_parser type
for http_get_path.

src/http_ana.c

index 63ee76034992638cee5afd7ae268fed7ab1d0e25..da436e7932f8a8a3890f241bdce62664c9b9dd8d 100644 (file)
@@ -203,40 +203,44 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
         * used. It is a workaround to let HTTP/2 health-checks work as
         * expected.
         */
-       if (unlikely((sess->fe->monitor_uri_len != 0) &&
-                    ((*sess->fe->monitor_uri == '/' && isteq(http_get_path(htx_sl_req_uri(sl)),
-                                                             ist2(sess->fe->monitor_uri, sess->fe->monitor_uri_len))) ||
-                     isteq(htx_sl_req_uri(sl), ist2(sess->fe->monitor_uri, sess->fe->monitor_uri_len))))) {
-               /*
-                * We have found the monitor URI
-                */
-               struct acl_cond *cond;
+       if (unlikely(sess->fe->monitor_uri_len != 0)) {
+               const struct ist monitor_uri = ist2(sess->fe->monitor_uri,
+                                                   sess->fe->monitor_uri_len);
+
+               if ((istptr(monitor_uri)[0] == '/' &&
+                    isteq(http_get_path(htx_sl_req_uri(sl)), monitor_uri)) ||
+                   isteq(htx_sl_req_uri(sl), monitor_uri)) {
+                       /*
+                        * We have found the monitor URI
+                        */
+                       struct acl_cond *cond;
 
-               s->flags |= SF_MONITOR;
-               _HA_ATOMIC_INC(&sess->fe->fe_counters.intercepted_req);
+                       s->flags |= SF_MONITOR;
+                       _HA_ATOMIC_INC(&sess->fe->fe_counters.intercepted_req);
 
-               /* Check if we want to fail this monitor request or not */
-               list_for_each_entry(cond, &sess->fe->mon_fail_cond, list) {
-                       int ret = acl_exec_cond(cond, sess->fe, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
+                       /* Check if we want to fail this monitor request or not */
+                       list_for_each_entry(cond, &sess->fe->mon_fail_cond, list) {
+                               int ret = acl_exec_cond(cond, sess->fe, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL);
 
-                       ret = acl_pass(ret);
-                       if (cond->pol == ACL_COND_UNLESS)
-                               ret = !ret;
+                               ret = acl_pass(ret);
+                               if (cond->pol == ACL_COND_UNLESS)
+                                       ret = !ret;
 
-                       if (ret) {
-                               /* we fail this request, let's return 503 service unavail */
-                               txn->status = 503;
-                               if (!(s->flags & SF_ERR_MASK))
-                                       s->flags |= SF_ERR_LOCAL; /* we don't want a real error here */
-                               goto return_prx_cond;
+                               if (ret) {
+                                       /* we fail this request, let's return 503 service unavail */
+                                       txn->status = 503;
+                                       if (!(s->flags & SF_ERR_MASK))
+                                               s->flags |= SF_ERR_LOCAL; /* we don't want a real error here */
+                                       goto return_prx_cond;
+                               }
                        }
-               }
 
-               /* nothing to fail, let's reply normally */
-               txn->status = 200;
-               if (!(s->flags & SF_ERR_MASK))
-                       s->flags |= SF_ERR_LOCAL; /* we don't want a real error here */
-               goto return_prx_cond;
+                       /* nothing to fail, let's reply normally */
+                       txn->status = 200;
+                       if (!(s->flags & SF_ERR_MASK))
+                               s->flags |= SF_ERR_LOCAL; /* we don't want a real error here */
+                       goto return_prx_cond;
+               }
        }
 
        /*