Skip to content

Commit 7bb1322

Browse files
author
Stephane Landelle
committed
Cache url inside UriComponents, close AsyncHttpClient#688
1 parent b8e0c46 commit 7bb1322

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

api/src/main/java/org/asynchttpclient/uri/UriComponents.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public static UriComponents create(UriComponents context, final String originalU
4141
private final int port;
4242
private final String query;
4343
private final String path;
44+
private String url;
4445

4546
public UriComponents(String scheme,//
4647
String userInfo,//
@@ -91,19 +92,22 @@ public URI toURI() throws URISyntaxException {
9192
}
9293

9394
public String toUrl() {
94-
StringBuilder sb = new StringBuilder();
95-
sb.append(scheme).append("://");
96-
if (userInfo != null)
97-
sb.append(userInfo).append('@');
98-
sb.append(host);
99-
if (port != -1)
100-
sb.append(':').append(port);
101-
if (path != null)
102-
sb.append(path);
103-
if (query != null)
104-
sb.append('?').append(query);
105-
106-
return sb.toString();
95+
if (url == null) {
96+
StringBuilder sb = new StringBuilder();
97+
sb.append(scheme).append("://");
98+
if (userInfo != null)
99+
sb.append(userInfo).append('@');
100+
sb.append(host);
101+
if (port != -1)
102+
sb.append(':').append(port);
103+
if (path != null)
104+
sb.append(path);
105+
if (query != null)
106+
sb.append('?').append(query);
107+
108+
url = sb.toString();
109+
}
110+
return url;
107111
}
108112

109113
public String toRelativeUrl() {

providers/netty/src/main/java/org/asynchttpclient/providers/netty/handler/Protocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ protected boolean exitAfterHandlingRedirect(//
125125
final String initialPoolKey = channelManager.getPoolKey(future);
126126

127127
future.setURI(uri);
128-
String newUrl = uri.toString();
128+
String newUrl = uri.toUrl();
129129
if (request.getURI().getScheme().startsWith(WEBSOCKET)) {
130130
newUrl = newUrl.replaceFirst(HTTP, WEBSOCKET);
131131
}

providers/netty/src/main/java/org/asynchttpclient/providers/netty/request/NettyRequestFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private String requestUri(UriComponents uri, ProxyServer proxyServer, HttpMethod
7777
return getAuthority(uri);
7878

7979
else if (proxyServer != null && !(useProxyConnect(uri) && config.isUseRelativeURIsWithConnectProxies()))
80-
return uri.toString();
80+
return uri.toUrl();
8181

8282
else {
8383
String path = getNonEmptyPath(uri);

0 commit comments

Comments
 (0)