Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions client/src/main/java/org/asynchttpclient/uri/Uri.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Locale;

import static org.asynchttpclient.util.Assertions.assertNotEmpty;
import static org.asynchttpclient.util.MiscUtils.isEmpty;
Expand All @@ -43,15 +44,18 @@
private final boolean webSocket;

public Uri(String scheme, @Nullable String userInfo, String host, int port, String path, @Nullable String query, @Nullable String fragment) {
this.scheme = assertNotEmpty(scheme, "scheme");
// rfc3986#section-3.1: schemes are case-insensitive, and validateSupportedScheme accepts any
// case. UriParser lowercases the schemes it parses; normalizing here keeps the constructor and
// withNewScheme consistent with it, so secured can't come out false for an "HTTPS" Uri.
this.scheme = assertNotEmpty(scheme, "scheme").toLowerCase(Locale.ROOT);
this.userInfo = userInfo;
this.host = assertNotEmpty(host, "host");
this.port = port;
this.path = path;
this.query = query;
this.fragment = fragment;
secured = HTTPS.equals(scheme) || WSS.equals(scheme);
webSocket = WS.equals(scheme) || WSS.equalsIgnoreCase(scheme);
secured = HTTPS.equals(this.scheme) || WSS.equals(this.scheme);
webSocket = WS.equals(this.scheme) || WSS.equals(this.scheme);
}

public static Uri create(String originalUrl) {
Expand Down Expand Up @@ -142,7 +146,7 @@
}

/**
* @return [scheme]://[hostname](:[port])/path. Port is omitted if it matches the scheme's default one.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / compile-and-check

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 11)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 25)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 21)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 17)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (macos-latest, 25)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (macos-latest, 21)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (macos-latest, 11)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.

Check warning on line 149 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (macos-latest, 17)

[MissingSummary] A summary fragment is required; consider using the value of the @return block as a summary fragment instead.
*/
public String toBaseUrl() {
StringBuilder sb = StringBuilderPool.DEFAULT.stringBuilder();
Expand Down Expand Up @@ -221,7 +225,7 @@
}

@Override
public boolean equals(Object obj) {

Check warning on line 228 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / compile-and-check

[EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.

Check warning on line 228 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 11)

[EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.

Check warning on line 228 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 17)

[EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.

Check warning on line 228 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (macos-latest, 11)

[EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.

Check warning on line 228 in client/src/main/java/org/asynchttpclient/uri/Uri.java

View workflow job for this annotation

GitHub Actions / test (macos-latest, 17)

[EqualsGetClass] Prefer instanceof to getClass when implementing Object#equals.
if (this == obj) {
return true;
}
Expand Down
22 changes: 22 additions & 0 deletions client/src/test/java/org/asynchttpclient/uri/UriTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ public void testWithNewScheme() {
assertEquals("https://user@example.com:44/path/path2?query=4", newUri.toUrl(), "toUrl returned incorrect url");
}

@RepeatedIfExceptionsTest(repeats = 5)
public void testUpperCaseSchemeIsSecured() {
Uri uri = new Uri("HTTPS", null, "example.com", -1, "/", null, null);
Uri.validateSupportedScheme(uri);
assertTrue(uri.isSecured(), "HTTPS must be secured");
assertEquals(443, uri.getSchemeDefaultPort());
assertEquals(443, uri.getExplicitPort());

Uri wss = new Uri("WSS", null, "example.com", -1, "/", null, null);
assertTrue(wss.isSecured(), "WSS must be secured");
assertTrue(wss.isWebSocket());
}

@RepeatedIfExceptionsTest(repeats = 5)
public void testMixedCaseSchemeIsNormalized() {
Uri uri = new Uri("HtTp", "user", "example.com", 44, "/path", "query=4", null);
assertEquals("http", uri.getScheme());
assertEquals("http://user@example.com:44/path?query=4", uri.toUrl());
assertEquals(uri, new Uri("http", "user", "example.com", 44, "/path", "query=4", null));
assertTrue(uri.withNewScheme("HTTPS").isSecured());
}

@RepeatedIfExceptionsTest(repeats = 5)
public void testWithNewQuery() {
Uri uri = new Uri("http", "user", "example.com", 44, "/path/path2", "query=4", null);
Expand Down
Loading