Skip to content

Require a scheme separator for absolute URIs - #3721

Merged
velo merged 2 commits into
OpenFeign:masterfrom
sharanggupta:absolute-uri-needs-scheme-separator
Nov 27, 2026
Merged

velo merged 2 commits into
OpenFeign:masterfrom
sharanggupta:absolute-uri-needs-scheme-separator

Conversation

@sharanggupta

Copy link
Copy Markdown
Contributor

UriUtils.isAbsolute only checks for an http prefix, so a relative uri such as @RequestLine("GET httpbin/get") or a JAX-RS @Path("httproutes") is rejected with "url values must be not be absolute.", and httpbin.org is accepted as a target. It now requires http:// or https://, still without regard to case.

`UriUtils.isAbsolute` only checked for an `http` prefix, so a relative
uri such as `httpbin/get` was rejected as absolute and `httpbin.org` was
accepted as a target. It now requires `http://` or `https://`.

@utafrali utafrali left a comment

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 fix is correct: requiring :// after the scheme eliminates both false positives (httpbin.org accepted as absolute) and false negatives (httpbin/get rejected as absolute). The two minor points are test-convention issues, not correctness problems, so the PR is approvable as-is.

.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.");
}

@@ -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.

Each scheme is now reported on its own, and UriUtils#isAbsolute has direct tests next to the other UriUtils cases.
@velo
velo enabled auto-merge (squash) November 27, 2026 18:28
@velo
velo merged commit 98047bd into OpenFeign:master Nov 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants