Skip to content

Commit 34ef0c2

Browse files
committed
Wrapper for partition key w/ proxy, close #AsyncHttpClient#932
1 parent 0cd4997 commit 34ef0c2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

api/src/main/java/org/asynchttpclient/channel/pool/ConnectionPoolPartitioning.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,33 @@
1818

1919
public interface ConnectionPoolPartitioning {
2020

21-
Object getPartitionKey(Uri uri, ProxyServer proxy);
21+
public class ProxyPartitionKey {
22+
private final String proxyUrl;
23+
private final String targetHostBaseUrl;
24+
25+
public ProxyPartitionKey(String proxyUrl, String targetHostBaseUrl) {
26+
this.proxyUrl = proxyUrl;
27+
this.targetHostBaseUrl = targetHostBaseUrl;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return new StringBuilder()//
33+
.append("ProxyPartitionKey(proxyUrl=").append(proxyUrl)//
34+
.append(", targetHostBaseUrl=").append(targetHostBaseUrl)//
35+
.toString();
36+
}
37+
}
38+
39+
Object getPartitionKey(Uri uri, ProxyServer proxyServer);
2240

2341
public enum PerHostConnectionPoolPartitioning implements ConnectionPoolPartitioning {
2442

2543
INSTANCE;
2644

27-
@Override
28-
public String getPartitionKey(Uri uri, ProxyServer proxyServer) {
29-
String serverPart = AsyncHttpProviderUtils.getBaseUrl(uri);
30-
return proxyServer != null ? proxyServer.getUrl() + serverPart : serverPart;
45+
public Object getPartitionKey(Uri uri, ProxyServer proxyServer) {
46+
String targetHostBaseUrl = AsyncHttpProviderUtils.getBaseUrl(uri);
47+
return proxyServer != null ? new ProxyPartitionKey(proxyServer.getUrl(), targetHostBaseUrl) : targetHostBaseUrl;
3148
}
3249
}
3350
}

0 commit comments

Comments
 (0)