Skip to content

Commit

Permalink
#472 fix: support "accounts.google.com:443" in addition to "https://a…
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev authored and valfirst committed Feb 8, 2025
1 parent 6f4b60d commit 4e78ac1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,12 @@ boolean isNonProxyHost(HttpRequest httpRequest) {
private static String extractHost(HttpRequest httpRequest) {
// skip upstream proxy configuration because the host is defined as proxy exception / non-proxy hosts
// therefore we need to cast it to URL
URL url = null;
try {
url = new URL(httpRequest.uri());
return new URL(httpRequest.uri()).getHost();
} catch (MalformedURLException e) {
log.error("The requested URL is not valid.", e);
log.debug("The requested URL \"{}\" is not valid: {}", httpRequest.uri(), e.toString());
return httpRequest.uri().replaceFirst("(.+):\\d+", "$1");
}
return url == null ? null : url.getHost();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class BrowserUpProxyServerTest {
@Test
void detectsNonProxyHosts() {
void detectsNonProxyHosts_byURL() {
BrowserUpProxyServer proxy = new BrowserUpProxyServer();
proxy.setChainedProxyNonProxyHosts(List.of("127.0.0.1", "*.example.com"));

Expand All @@ -25,6 +25,20 @@ void detectsNonProxyHosts() {
assertThat(proxy.isNonProxyHost(request("https://foo-example.com")), equalTo(false));
}

@Test
void detectsNonProxyHosts_byHostname() {
BrowserUpProxyServer proxy = new BrowserUpProxyServer();
proxy.setChainedProxyNonProxyHosts(List.of("127.0.0.1", "*.example.com"));

assertThat(proxy.isNonProxyHost(request("127.0.0.1:36915")), equalTo(true));
assertThat(proxy.isNonProxyHost(request("127.0.0.2:8080")), equalTo(false));
assertThat(proxy.isNonProxyHost(request("foo.example.com")), equalTo(true));
assertThat(proxy.isNonProxyHost(request("bar.example.com:443")), equalTo(true));
assertThat(proxy.isNonProxyHost(request("example.com")), equalTo(false));
assertThat(proxy.isNonProxyHost(request("a.b.c.foo.example.com")), equalTo(true));
assertThat(proxy.isNonProxyHost(request("foo-example.com")), equalTo(false));
}

@Test
void nonProxyHostsNotSpecified() {
BrowserUpProxyServer proxy = new BrowserUpProxyServer();
Expand Down

0 comments on commit 4e78ac1

Please sign in to comment.