diff --git a/CHANGELOG.md b/CHANGELOG.md index 2900be6..0a74ec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ * Added logging for process output on debugging mode +* Introduced system property `use_proxy` to toggle proxy detection and info request + (default is `true` to keep old behaviour) + ## 1.8.7 - May 24, 2022 * Paths in classpath are specified relative to appdir to avoid excessively long command lines. diff --git a/core/src/main/java/io/github/bekoenig/getdown/data/SysProps.java b/core/src/main/java/io/github/bekoenig/getdown/data/SysProps.java index 5c6b143..5478fde 100644 --- a/core/src/main/java/io/github/bekoenig/getdown/data/SysProps.java +++ b/core/src/main/java/io/github/bekoenig/getdown/data/SysProps.java @@ -134,6 +134,14 @@ public static boolean direct() { return Boolean.getBoolean("direct"); } + /** + * If false, Getdown will not detect proxy or request proxy info. Default is true. + * Usage: {@code -Duse_proxy=false}. + */ + public static boolean useProxy() { + return !"false".equals(System.getProperty("use_proxy")); + } + /** * If true, Getdown will always try to connect without proxy settings even it a proxy is set * in {@code proxy.txt}. If direct access is possible it will not clear {@code proxy.txt}, it diff --git a/core/src/test/java/io/github/bekoenig/getdown/data/SysPropsTest.java b/core/src/test/java/io/github/bekoenig/getdown/data/SysPropsTest.java index cd8dc36..2b135f4 100644 --- a/core/src/test/java/io/github/bekoenig/getdown/data/SysPropsTest.java +++ b/core/src/test/java/io/github/bekoenig/getdown/data/SysPropsTest.java @@ -94,4 +94,52 @@ void test_hostWhitelist_defined() { assertThat(hostWhitelist).isEqualTo("app1.foo.com,app2.bar.com,app3.baz.com"); } + @Test + @ClearSystemProperty(key = "use_proxy") + void test_useProxy_undefined() { + // GIVEN + + // WHEN + boolean useProxy = SysProps.useProxy(); + + // THEN + assertThat(useProxy).isTrue(); + } + + @Test + @SetSystemProperty(key = "use_proxy", value = "") + void test_useProxy_defined() { + // GIVEN + + // WHEN + boolean useProxy = SysProps.useProxy(); + + // THEN + assertThat(useProxy).isTrue(); + } + + @Test + @SetSystemProperty(key = "use_proxy", value = "true") + void test_useProxy_true() { + // GIVEN + + // WHEN + boolean useProxy = SysProps.useProxy(); + + // THEN + assertThat(useProxy).isTrue(); + } + + @Test + @SetSystemProperty(key = "use_proxy", value = "false") + void test_useProxy_false() { + // GIVEN + + // WHEN + boolean useProxy = SysProps.useProxy(); + + // THEN + assertThat(useProxy).isFalse(); + } + } diff --git a/launcher/src/main/java/io/github/bekoenig/getdown/launcher/Getdown.java b/launcher/src/main/java/io/github/bekoenig/getdown/launcher/Getdown.java index 57441ea..37e0b9f 100644 --- a/launcher/src/main/java/io/github/bekoenig/getdown/launcher/Getdown.java +++ b/launcher/src/main/java/io/github/bekoenig/getdown/launcher/Getdown.java @@ -176,6 +176,11 @@ protected void run() { } protected boolean detectProxy() { + if (!SysProps.useProxy()) { + LOGGER.info("Skipped proxy detection"); + return true; + } + // first we have to initialize our application to get the appbase URL, etc. LOGGER.info("Checking whether we need to use a proxy..."); try { @@ -213,7 +218,7 @@ protected void readConfig(boolean preloads) throws IOException { } protected void requestProxyInfo(boolean reinitAuth) { - if (_silent) { + if (_silent || !SysProps.useProxy()) { LOGGER.warn("Need a proxy, but we don't want to bother anyone. Exiting."); return; }