Skip to content

Commit fca3613

Browse files
author
Sheridan C Rawlins
committed
Check for null target in avoidProxy to prevent exceptions; Close #560.
1 parent e84ee12 commit fca3613

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

api/src/main/java/org/asynchttpclient/util/ProxyUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public static boolean avoidProxy(final ProxyServer proxyServer, final Request re
113113
*/
114114
public static boolean avoidProxy(final ProxyServer proxyServer, final String target) {
115115
if (proxyServer != null) {
116-
final String targetHost = target.toLowerCase(Locale.ENGLISH);
116+
final String targetHost = (target != null) ?
117+
target.toLowerCase(Locale.ENGLISH) : "";
117118

118119
List<String> nonProxyHosts = proxyServer.getNonProxyHosts();
119120

api/src/test/java/org/asynchttpclient/util/ProxyUtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,11 @@ public void testBasics() {
4444
proxyServer = new ProxyServer("foo", 1234);
4545
proxyServer.addNonProxyHost("*.somewhere.org");
4646
assertFalse(ProxyUtils.avoidProxy(proxyServer, req));
47+
48+
// shouldn't crash
49+
req = new RequestBuilder("GET").setUrl("http:///badhost/foo").build();
50+
proxyServer = new ProxyServer("foo", 1234);
51+
proxyServer.addNonProxyHost("*.somewhere.org");
52+
assertFalse(ProxyUtils.avoidProxy(proxyServer, req));
4753
}
4854
}

0 commit comments

Comments
 (0)