Skip to content

Commit ed1be29

Browse files
committed
("Setting url on RequestBuilder requires scheme to use // separator")
1 parent 026e34f commit ed1be29

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,19 @@ private String buildUrl(String url) {
307307
if (uri.getAuthority() != null) {
308308
buildedUrl.append(uri.getAuthority());
309309
}
310-
buildedUrl.append(uri.getRawPath());
310+
if (uri.getRawPath() != null) {
311+
buildedUrl.append(uri.getRawPath());
312+
} else {
313+
// AHC-96
314+
// Let's try to derive it
315+
if (url.indexOf("://") == -1) {
316+
String s = buildedUrl.toString();
317+
url = s + url.substring(uri.getScheme().length() + 1);
318+
return buildUrl(url);
319+
} else {
320+
throw new IllegalArgumentException("Invalid url " + uri.toString());
321+
}
322+
}
311323

312324
if (uri.getRawQuery() != null && !uri.getRawQuery().equals("")) {
313325
String[] queries = uri.getRawQuery().split("&");

src/test/java/com/ning/http/client/async/AsyncProvidersBasicTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,4 +1581,16 @@ public void headShouldNotAllowBody() throws IllegalArgumentException, IOExceptio
15811581
builder.setBody("Boo!");
15821582
builder.execute();
15831583
}
1584+
1585+
protected String getBrokenTargetUrl() {
1586+
return String.format("http:127.0.0.1:%d/foo/test", port1);
1587+
}
1588+
1589+
@Test(groups = {"standalone", "default_provider"})
1590+
public void invalidUri() throws Exception {
1591+
AsyncHttpClient c = getAsyncHttpClient(null);
1592+
AsyncHttpClient.BoundRequestBuilder builder = c.prepareGet(getBrokenTargetUrl());
1593+
Response r = c.executeRequest(builder.build()).get();
1594+
assertEquals(200, r.getStatusCode());
1595+
}
15841596
}

0 commit comments

Comments
 (0)