Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1306e6d committed Jun 2, 2024
1 parent 836380d commit 9a614c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Objects;
import javax.annotation.Nullable;

import static io.servicetalk.buffer.api.CharSequences.regionMatches;
import static io.servicetalk.http.api.UriComponentType.FRAGMENT;
import static io.servicetalk.http.api.UriComponentType.HOST_NON_IP;
import static io.servicetalk.http.api.UriComponentType.PATH;
Expand Down Expand Up @@ -173,7 +172,7 @@ final class Uri3986 implements Uri {
if (i == 0) {
throw new IllegalArgumentException("Invalid URI format: no scheme before colon (':')");
}
parsedScheme = getLowerCaseScheme(uri.substring(0, i));
parsedScheme = getLowerCaseScheme(uri, i);
begin = ++i;
// We don't enforce the following, browsers still generate these types of requests.
// https://tools.ietf.org/html/rfc3986#section-3.3
Expand All @@ -200,16 +199,13 @@ final class Uri3986 implements Uri {
this.uri = uri;
}

private static String getLowerCaseScheme(String scheme) {
if (regionMatches(scheme, true, 0, HTTP_SCHEME, 0, HTTP_SCHEME.length())) {
if (scheme.length() == 4) {
return HTTP_SCHEME;
}
if (scheme.length() == 5 && (scheme.charAt(4) == 's' || scheme.charAt(4) == 'S')) {
return HTTPS_SCHEME;
}
private static String getLowerCaseScheme(final String uri, final int endIndex) {
if (endIndex == 4 && uri.regionMatches(true, 0, HTTP_SCHEME, 0, 4)) {
return HTTP_SCHEME;
} else if (endIndex == 5 && uri.regionMatches(true, 0, HTTPS_SCHEME, 0, 5)) {
return HTTPS_SCHEME;
}
return scheme.toLowerCase(Locale.ENGLISH);
return uri.substring(0, endIndex).toLowerCase(Locale.ENGLISH);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalToIgnoringCase;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -181,9 +180,6 @@ void reuseWellKnownScheme() {
String https1 = new Uri3986("https://test.com").scheme();
String https2 = new Uri3986("HTTPS://test.com").scheme();
assertThat("different https", https1, sameInstance(https2));

String httpss = new Uri3986("HTTPSS://test.com").scheme();
assertThat("same https and httpss", https1, not(sameInstance(httpss)));
}

@Test
Expand Down

0 comments on commit 9a614c5

Please sign in to comment.