]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: Store monitor_uri as a `struct ist`
authorTim Duesterhus <tim@bastelstu.be>
Fri, 4 Mar 2022 23:52:40 +0000 (00:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Mar 2022 06:51:27 +0000 (07:51 +0100)
The monitor_uri is already processed as an ist in `http_wait_for_request`, lets
also just store it as such.

see 0643b0e7e ("MINOR: proxy: Make `header_unique_id` a `struct ist`") for a
very similar past commit.

include/haproxy/proxy-t.h
src/cfgparse-listen.c
src/http_ana.c
src/proxy.c

index 421f900e29c9c2b5954affe246a73950389ab29a..13e722fbf26c5ebd3ed92e2817f42e6b72846a17 100644 (file)
@@ -322,8 +322,7 @@ struct proxy {
        int srvtcpka_cnt;                       /* The maximum number of keepalive probes TCP should send before dropping the connection. (server side) */
        int srvtcpka_idle;                      /* The time (in seconds) the connection needs to remain idle before TCP starts sending keepalive probes. (server side) */
        int srvtcpka_intvl;                     /* The time (in seconds) between individual keepalive probes. (server side) */
-       int monitor_uri_len;                    /* length of the string above. 0 if unused */
-       char *monitor_uri;                      /* a special URI to which we respond with HTTP/200 OK */
+       struct ist monitor_uri;                 /* a special URI to which we respond with HTTP/200 OK */
        struct list mon_fail_cond;              /* list of conditions to fail monitoring requests (chained) */
        struct {                                /* WARNING! check proxy_reset_timeouts() in proxy.h !!! */
                int client;                     /* client I/O timeout (in ticks) */
index 5deec5e6bd66003621649b70059e5968679f57a1..eb58b2eb16f1ab4e1d4a2421549efccceae29274 100644 (file)
@@ -575,13 +575,10 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                        goto out;
                }
 
-               free(curproxy->monitor_uri);
-               curproxy->monitor_uri_len = strlen(args[1]);
-               curproxy->monitor_uri = calloc(1, curproxy->monitor_uri_len + 1);
-               if (!curproxy->monitor_uri)
+               istfree(&curproxy->monitor_uri);
+               curproxy->monitor_uri = istdup(ist(args[1]));
+               if (!isttest(curproxy->monitor_uri))
                        goto alloc_error;
-               memcpy(curproxy->monitor_uri, args[1], curproxy->monitor_uri_len);
-               curproxy->monitor_uri[curproxy->monitor_uri_len] = '\0';
 
                goto out;
        }
index f33eb7790e5e78f33b76f55b20e1cf0b66d4facb..b60927e527a1e1a1192e9eca79594fe8db260701 100644 (file)
@@ -203,9 +203,8 @@ 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)) {
-               const struct ist monitor_uri = ist2(sess->fe->monitor_uri,
-                                                   sess->fe->monitor_uri_len);
+       if (unlikely(isttest(sess->fe->monitor_uri))) {
+               const struct ist monitor_uri = sess->fe->monitor_uri;
                struct http_uri_parser parser = http_uri_parser_init(htx_sl_req_uri(sl));
 
                if ((istptr(monitor_uri)[0] == '/' &&
index dbcab474fa48daf2b1a685e28ac3bb56c214634e..79aa3f437fd9c241e53b7bf5def1aa481ea29bc0 100644 (file)
@@ -156,7 +156,7 @@ void free_proxy(struct proxy *p)
        free(p->lbprm.arg_str);
        free(p->server_state_file_name);
        free(p->capture_name);
-       free(p->monitor_uri);
+       istfree(&p->monitor_uri);
        free(p->rdp_cookie_name);
        free(p->invalid_rep);
        free(p->invalid_req);
@@ -1274,7 +1274,7 @@ int proxy_cfg_ensure_no_http(struct proxy *curproxy)
                ha_warning("cookie will be ignored for %s '%s' (needs 'mode http').\n",
                           proxy_type_str(curproxy), curproxy->id);
        }
-       if (curproxy->monitor_uri != NULL) {
+       if (isttest(curproxy->monitor_uri)) {
                ha_warning("monitor-uri will be ignored for %s '%s' (needs 'mode http').\n",
                           proxy_type_str(curproxy), curproxy->id);
        }
@@ -1436,7 +1436,7 @@ void proxy_free_defaults(struct proxy *defproxy)
        ha_free(&defproxy->cookie_attrs);
        ha_free(&defproxy->lbprm.arg_str);
        ha_free(&defproxy->capture_name);
-       ha_free(&defproxy->monitor_uri);
+       istfree(&defproxy->monitor_uri);
        ha_free(&defproxy->defbe.name);
        ha_free(&defproxy->conn_src.iface_name);
        ha_free(&defproxy->fwdfor_hdr_name); defproxy->fwdfor_hdr_len = 0;
@@ -1711,9 +1711,8 @@ static int proxy_defproxy_cpy(struct proxy *curproxy, const struct proxy *defpro
                curproxy->timeout.tarpit = defproxy->timeout.tarpit;
                curproxy->timeout.httpreq = defproxy->timeout.httpreq;
                curproxy->timeout.httpka = defproxy->timeout.httpka;
-               if (defproxy->monitor_uri)
-                       curproxy->monitor_uri = strdup(defproxy->monitor_uri);
-               curproxy->monitor_uri_len = defproxy->monitor_uri_len;
+               if (isttest(defproxy->monitor_uri))
+                       curproxy->monitor_uri = istdup(defproxy->monitor_uri);
                if (defproxy->defbe.name)
                        curproxy->defbe.name = strdup(defproxy->defbe.name);