Skip to content

Commit 050895e

Browse files
committed
Improve proxy address formatting in ConfigFetcher and update related tests
1 parent a4a5f58 commit 050895e

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/main/java/com/configcat/ConfigFetcher.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.Closeable;
77
import java.io.IOException;
8+
import java.net.InetSocketAddress;
89
import java.net.Proxy;
910
import java.net.SocketTimeoutException;
1011
import java.util.UUID;
@@ -282,8 +283,11 @@ private String getProxyAddress() {
282283
if (proxy == null || proxy.type() == Proxy.Type.DIRECT) {
283284
return null;
284285
}
285-
286-
return proxy.toString();
286+
if (proxy.address() instanceof InetSocketAddress) {
287+
InetSocketAddress addr = (InetSocketAddress) proxy.address();
288+
return proxy.type() + " @ " + addr.getHostString() + ":" + addr.getPort();
289+
}
290+
return proxy.type() + " @ " + proxy.address();
287291
}
288292

289293
private Result<Config> deserializeConfig(String json, String cfRayId) {

src/test/java/com/configcat/ConfigFetcherTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public void getProxyUriWhenProxyIsHTTPReturnsFormattedHttpProxyUri() throws IOEx
512512

513513
String result = getProxyUriUsingReflection(fetcher);
514514

515-
assertEquals("HTTP @ proxy.example.com/<unresolved>:8080", result);
515+
assertEquals("HTTP @ proxy.example.com:8080", result);
516516
fetcher.close();
517517
}
518518

@@ -525,7 +525,7 @@ public void getProxyUriWhenProxyIsSOCKSReturnsFormattedSocks5ProxyUri() throws I
525525

526526
String result = getProxyUriUsingReflection(fetcher);
527527

528-
assertEquals("SOCKS @ socks.example.com/<unresolved>:1080", result);
528+
assertEquals("SOCKS @ socks.example.com:1080", result);
529529
fetcher.close();
530530
}
531531

0 commit comments

Comments
 (0)