Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion core/src/main/java/feign/template/UriUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ public static String decode(String value, Charset charset) {
* @return true if the uri is absolute.
*/
public static boolean isAbsolute(String uri) {
return uri != null && uri.regionMatches(true, 0, "http", 0, 4);
return uri != null
&& (uri.regionMatches(true, 0, "http://", 0, 7)
|| uri.regionMatches(true, 0, "https://", 0, 8));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions core/src/test/java/feign/RequestTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ void canInsertAbsoluteHrefWithCaseInsensitiveScheme() {
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These integration-level tests are useful, but UriUtils.isAbsolute is a pure utility method and UriUtilsTest.java is the natural home for direct unit tests of it. Adding a few cases there (e.g. httpbin/get returns false, httpbin.org returns false, HTTP://X returns true) would make the unit contract explicit and easier to find when the method changes in the future.


@Test
void acceptsRelativeUriStartingWithHttp() {
RequestTemplate template =
new RequestTemplate()
.method(HttpMethod.GET)
.uri("httpbin/get")
.target("https://example.com");

assertThat(template).hasUrl("https://example.com/httpbin/get");
}

@Test
void rejectsTargetWithoutScheme() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new RequestTemplate().target("httpbin.org"))
.withMessage("target values must be absolute.");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The for loop over schemes means a single test failure won't tell you which variant broke. The project already uses @ParameterizedTest + @MethodSource for data-driven cases elsewhere; that pattern would be more consistent here and give a clearer failure message per scheme:

@ParameterizedTest
@ValueSource(strings = {"HTTP", "HTTPS", "hTtP", "hTtPs"})
void rejectsAbsoluteUriWithCaseInsensitiveScheme(String scheme) {
  assertThatExceptionOfType(IllegalArgumentException.class)
      .isThrownBy(() -> new RequestTemplate().uri(scheme + "://example.com/path"))
      .withMessage("url values must be not be absolute.");
}

@Test
void rejectsAbsoluteUriWithCaseInsensitiveScheme() {
for (String scheme : Arrays.asList("HTTP", "HTTPS", "hTtP", "hTtPs")) {
Expand Down