Skip to content

Commit fb1a88a

Browse files
author
Stephane Landelle
committed
Add UriComponents.toRelativeUrl, close AsyncHttpClient#677
1 parent 5ca4fa4 commit fb1a88a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import java.net.URI;
1616
import java.net.URISyntaxException;
1717

18-
public class UriComponents {
18+
import org.asynchttpclient.util.MiscUtils;
1919

20+
public class UriComponents {
21+
2022
public static UriComponents create(String originalUrl) {
2123
return create(null, originalUrl);
2224
}
@@ -104,6 +106,18 @@ public String toUrl() {
104106
return sb.toString();
105107
}
106108

109+
public String toRelativeUrl() {
110+
StringBuilder sb = new StringBuilder();
111+
if (MiscUtils.isNonEmpty(path))
112+
sb.append(path);
113+
else
114+
sb.append('/');
115+
if (query != null)
116+
sb.append('?').append(query);
117+
118+
return sb.toString();
119+
}
120+
107121
@Override
108122
public String toString() {
109123
// for now, but might change

0 commit comments

Comments
 (0)