Skip to content

Commit

Permalink
feat: added property to toggle proxy detection and info request
Browse files Browse the repository at this point in the history
  • Loading branch information
bekoenig committed Aug 16, 2024
1 parent de12e12 commit 8e940f1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8e940f1

Please sign in to comment.