]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: httpclient: allow to disable the DNS resolvers of the httpclient
authorWilliam Lallemand <wlallemand@haproxy.org>
Thu, 11 May 2023 19:08:38 +0000 (21:08 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Thu, 11 May 2023 19:25:37 +0000 (21:25 +0200)
httpclient.resolvers.disabled allow to disable completely the resolvers
of the httpclient, prevents the creation of the "default" resolvers
section, and does not insert the http do-resolve rule in the proxies.

doc/configuration.txt
src/http_client.c

index 1ccc91b042e71caf9c5aa70bc730d69224b9651f..aabbe8e2bddd4a72968a1fd61d23e899fa3479be 100644 (file)
@@ -1068,6 +1068,7 @@ The following keywords are supported in the "global" section :
    - h1-case-adjust-file
    - h2-workaround-bogus-websocket-clients
    - hard-stop-after
+   - httpclient.resolvers.disabled
    - httpclient.resolvers.id
    - httpclient.resolvers.prefer
    - httpclient.ssl.ca-file
@@ -1681,6 +1682,12 @@ hard-stop-after <time>
 
   See also: grace
 
+httpclient.resolvers.disabled <on|off>
+  Disable the DNS resolution of the httpclient. Prevent the creation of the
+  "default" resolvers section.
+
+  Default value is off.
+
 httpclient.resolvers.id <resolvers id>
   This option defines the resolvers section with which the httpclient will try
   to resolve.
index af30c8e58e80629d54929762ed78477c10561725..2c33c85a27e51a57f9824d5b77cb25dabb9b8353 100644 (file)
@@ -53,6 +53,7 @@ static struct applet httpclient_applet;
 static int hard_error_resolvers = 0;
 static char *resolvers_id = NULL;
 static char *resolvers_prefer = NULL;
+static int resolvers_disabled = 0;
 
 /* --- This part of the file implement an HTTP client over the CLI ---
  * The functions will be  starting by "hc_cli" for "httpclient cli"
@@ -1138,6 +1139,10 @@ static int httpclient_resolve_init(struct proxy *px)
               { "" }
        };
 
+
+       if (resolvers_disabled)
+               return 0;
+
        if (!resolvers_id)
                resolvers_id = strdup("default");
 
@@ -1432,6 +1437,25 @@ static int httpclient_parse_global_resolvers(char **args, int section_type, stru
        return 0;
 }
 
+/* config parser for global "httpclient.resolvers.disabled", accepts "on" or "off" */
+static int httpclient_parse_global_resolvers_disabled(char **args, int section_type, struct proxy *curpx,
+                                      const struct proxy *defpx, const char *file, int line,
+                                      char **err)
+{
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       if (strcmp(args[1], "on") == 0)
+               resolvers_disabled = 1;
+       else if (strcmp(args[1], "off") == 0)
+               resolvers_disabled = 0;
+       else {
+               memprintf(err, "'%s' expects either 'on' or 'off' but got '%s'.", args[0], args[1]);
+               return -1;
+       }
+       return 0;
+}
+
 static int httpclient_parse_global_prefer(char **args, int section_type, struct proxy *curpx,
                                         const struct proxy *defpx, const char *file, int line,
                                         char **err)
@@ -1497,6 +1521,7 @@ static int httpclient_parse_global_verify(char **args, int section_type, struct
 #endif /* ! USE_OPENSSL */
 
 static struct cfg_kw_list cfg_kws = {ILH, {
+       { CFG_GLOBAL, "httpclient.resolvers.disabled", httpclient_parse_global_resolvers_disabled },
        { CFG_GLOBAL, "httpclient.resolvers.id", httpclient_parse_global_resolvers },
        { CFG_GLOBAL, "httpclient.resolvers.prefer", httpclient_parse_global_prefer },
 #ifdef USE_OPENSSL