]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR/OPTIM: http_htx: lookup once http_errors section on check/init
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 18 Mar 2026 15:49:33 +0000 (16:49 +0100)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Mon, 23 Mar 2026 09:51:33 +0000 (10:51 +0100)
The previous patch has splitted the original proxy_check_errors()
function in two, so that check and init steps are performed separately.
However, this renders the code inefficient for "errorfiles" directive as
tree lookup on http-errors section is performed twice.

Optimize this by adding a reference to the section in conf_errors
structure. This is resolved during proxy_check_http_errors() and
proxy_finalize_http_errors() can reuse it.

No need to backport.

src/http_htx.c

index 61e5683e60586cada187b0b36fdd95f84a191aa2..dc18735e3b1c85599f9e60d35e652b8b37eab920 100644 (file)
@@ -49,6 +49,7 @@ struct conf_errors {
                } inl;                              /* for HTTP_ERR_DIRECTIVE_INLINE only */
                struct {
                        char *name;                 /* the http-errors section name */
+                       struct http_errors *resolved; /* resolved section pointer set via proxy_check_http_errors() */
                        enum http_err_import status[HTTP_ERR_SIZE]; /* list of status to import */
                } section;                          /* for HTTP_ERR_DIRECTIVE_SECTION only */
        } type;
@@ -2269,7 +2270,6 @@ static int proxy_finalize_http_errors(struct proxy *px)
 {
        struct conf_errors *conf_err, *conf_err_back;
        struct http_errors *http_errs;
-       int section_found;
        int rc;
 
        list_for_each_entry_safe(conf_err, conf_err_back, &px->conf.errors, list) {
@@ -2284,16 +2284,8 @@ static int proxy_finalize_http_errors(struct proxy *px)
                        break;
 
                case HTTP_ERR_DIRECTIVE_SECTION:
-                       section_found = 0;
-                       list_for_each_entry(http_errs, &http_errors_list, list) {
-                               if (strcmp(http_errs->id, conf_err->type.section.name) == 0) {
-                                       section_found = 1;
-                                       break;
-                               }
-                       }
-
-                       free(conf_err->type.section.name);
-                       if (section_found) {
+                       http_errs = conf_err->type.section.resolved;
+                       if (http_errs) {
                                for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
                                        if (conf_err->type.section.status[rc] == HTTP_ERR_IMPORT_NO)
                                                continue;
@@ -2360,6 +2352,7 @@ int proxy_check_http_errors(struct proxy *px)
                                }
                        }
 
+                       ha_free(&conf_err->type.section.name);
                        if (!section_found) {
                                ha_alert("proxy '%s': unknown http-errors section '%s' (at %s:%d).\n",
                                         px->id, conf_err->type.section.name, conf_err->file, conf_err->line);
@@ -2367,6 +2360,8 @@ int proxy_check_http_errors(struct proxy *px)
                                continue;
                        }
 
+                       conf_err->type.section.resolved = http_errs;
+
                        for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
                                if (conf_err->type.section.status[rc] == HTTP_ERR_IMPORT_EXPLICIT &&
                                    !http_errs->replies[rc]) {