Skip to content

Commit cfdaece

Browse files
author
Stephane Landelle
committed
Have a getUrl shortcut on Request without having to grab the UriComponents, close AsyncHttpClient#689
1 parent 7bb1322 commit cfdaece

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

api/src/main/java/org/asynchttpclient/Request.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public interface Request {
4747

4848
UriComponents getURI();
4949

50+
String getUrl();
51+
5052
/**
5153
* Return the InetAddress to override
5254
*

api/src/main/java/org/asynchttpclient/RequestBuilderBase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public RequestImpl(Request prototype) {
9999
}
100100
}
101101

102+
@Override
103+
public String getUrl() {
104+
return uri.toUrl();
105+
}
106+
102107
@Override
103108
public String getMethod() {
104109
return method;
@@ -229,7 +234,7 @@ public List<Param> getQueryParams() {
229234

230235
@Override
231236
public String toString() {
232-
StringBuilder sb = new StringBuilder(getURI().toUrl());
237+
StringBuilder sb = new StringBuilder(getUrl());
233238

234239
sb.append("\t");
235240
sb.append(method);

api/src/main/java/org/asynchttpclient/resumable/ResumableAsyncHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public AsyncHandler.STATE onHeadersReceived(HttpResponseHeaders headers) throws
197197
*/
198198
public Request adjustRequestRange(Request request) {
199199

200-
Long ri = resumableIndex.get(request.getURI().toUrl());
200+
Long ri = resumableIndex.get(request.getUrl());
201201
if (ri != null) {
202202
byteTransferred.set(ri);
203203
}

api/src/test/java/org/asynchttpclient/async/AsyncProvidersBasicTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void asyncProviderEncodingTest() throws Exception {
7373
AsyncHttpClient client = getAsyncHttpClient(null);
7474
try {
7575
Request request = new RequestBuilder("GET").setUrl(getTargetUrl() + "?q=+%20x").build();
76-
assertEquals(request.getURI().toUrl(), getTargetUrl() + "?q=%20%20x");
76+
assertEquals(request.getUrl(), getTargetUrl() + "?q=%20%20x");
7777

7878
String url = client.executeRequest(request, new AsyncCompletionHandler<String>() {
7979
@Override

api/src/test/java/org/asynchttpclient/async/RequestBuilderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void testEncodesQueryParameters() throws UnsupportedEncodingException {
7070
}
7171
String expValue = sb.toString();
7272
Request request = builder.build();
73-
assertEquals(request.getURI().toUrl(), "http://example.com/?name=" + expValue);
73+
assertEquals(request.getUrl(), "http://example.com/?name=" + expValue);
7474
}
7575
}
7676

@@ -93,7 +93,7 @@ public void testParsesQueryParams() throws IOException, ExecutionException, Inte
9393
.addQueryParam("param2", "value2")
9494
.build();
9595

96-
assertEquals(request.getURI().toUrl(), "http://foo.com/?param1=value1&param2=value2");
96+
assertEquals(request.getUrl(), "http://foo.com/?param1=value1&param2=value2");
9797
List<Param> params = request.getQueryParams();
9898
assertEquals(params.size(), 2);
9999
assertEquals(params.get(0), new Param("param1", "value1"));
@@ -104,14 +104,14 @@ public void testParsesQueryParams() throws IOException, ExecutionException, Inte
104104
public void testUserProvidedRequestMethod() {
105105
Request req = new RequestBuilder("ABC").setUrl("http://foo.com").build();
106106
assertEquals(req.getMethod(), "ABC");
107-
assertEquals(req.getURI().toUrl(), "http://foo.com/");
107+
assertEquals(req.getUrl(), "http://foo.com/");
108108
}
109109

110110
@Test(groups = {"standalone", "default_provider"})
111111
public void testPercentageEncodedUserInfo() {
112112
final Request req = new RequestBuilder("GET").setUrl("http://hello:wor%[email protected]").build();
113113
assertEquals(req.getMethod(), "GET");
114-
assertEquals(req.getURI().toUrl(), "http://hello:wor%[email protected]");
114+
assertEquals(req.getUrl(), "http://hello:wor%[email protected]");
115115
}
116116

117117
@Test(groups = {"standalone", "default_provider"})

providers/grizzly/src/main/java/org/asynchttpclient/providers/grizzly/filters/ProxyFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException {
6666
assert (context != null);
6767
Request req = context.getRequest();
6868
if (!secure) {
69-
request.setRequestURI(req.getURI().toUrl());
69+
request.setRequestURI(req.getUrl());
7070
}
7171
addProxyHeaders(getRealm(req), request);
7272
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void onFutureFailure(Channel channel, Throwable cause) {
137137
LOGGER.debug("Failed to recover from exception: {} with channel {}", cause, channel);
138138

139139
boolean printCause = cause != null && cause.getMessage() != null;
140-
String url = future.getURI().toUrl();
140+
String url = future.getUrl();
141141
String printedCause = printCause ? cause.getMessage() + " to " + url : url;
142142
ConnectException e = new ConnectException(printedCause);
143143
if (cause != null)

0 commit comments

Comments
 (0)