Skip to content

Commit 938b53d

Browse files
committed
Wrapper for partition key w/ proxy, close #AsyncHttpClient#932
1 parent e096ab6 commit 938b53d

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

src/main/java/com/ning/http/client/ConnectionPoolPartitioning.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,33 @@
1717

1818
public interface ConnectionPoolPartitioning {
1919

20-
Object getPartitionKey(Uri uri, ProxyServer proxyServer);
21-
22-
public enum PerHostConnectionPoolPartitioning implements ConnectionPoolPartitioning {
23-
24-
INSTANCE;
25-
26-
public String getPartitionKey(Uri uri, ProxyServer proxyServer) {
27-
String serverPart = AsyncHttpProviderUtils.getBaseUrl(uri);
28-
return proxyServer != null ? proxyServer.getUrl() + serverPart : serverPart;
29-
}
30-
}
20+
public class ProxyPartitionKey {
21+
private final String proxyUrl;
22+
private final String targetHostBaseUrl;
3123

24+
public ProxyPartitionKey(String proxyUrl, String targetHostBaseUrl) {
25+
this.proxyUrl = proxyUrl;
26+
this.targetHostBaseUrl = targetHostBaseUrl;
27+
}
28+
29+
@Override
30+
public String toString() {
31+
return new StringBuilder()//
32+
.append("ProxyPartitionKey(proxyUrl=").append(proxyUrl)//
33+
.append(", targetHostBaseUrl=").append(targetHostBaseUrl)//
34+
.toString();
35+
}
36+
}
37+
38+
Object getPartitionKey(Uri uri, ProxyServer proxyServer);
39+
40+
public enum PerHostConnectionPoolPartitioning implements ConnectionPoolPartitioning {
41+
42+
INSTANCE;
43+
44+
public Object getPartitionKey(Uri uri, ProxyServer proxyServer) {
45+
String targetHostBaseUrl = AsyncHttpProviderUtils.getBaseUrl(uri);
46+
return proxyServer != null ? new ProxyPartitionKey(proxyServer.getUrl(), targetHostBaseUrl) : targetHostBaseUrl;
47+
}
48+
}
3249
}

0 commit comments

Comments
 (0)