Allow null contextPath in ServerHttpRequest.Builder

The builder method required a non-null contextPath while the underlying
field, MutatedServerHttpRequest constructor, and RequestPath.parse all
accept null and treat it the same as an empty string. Relax the method
parameter to @Nullable so callers can clear the context path directly.

Closes gh-37099

Signed-off-by: Garvit Joshi <garvitjoshi9@gmail.com>
This commit is contained in:
Garvit Joshi
2026-08-24 17:18:17 +01:00
committed by rstoyanchev
parent 82cf15c60f
commit 8d4208f030
3 changed files with 14 additions and 2 deletions
@@ -194,6 +194,16 @@ class ServerHttpRequestTests {
assertThat(mutated.getURI().getRawPath()).isEqualTo("/other/path");
}
@Test
void mutateContextPathToNull() throws Exception {
ServerHttpRequest request = createRequest("/context/path", "/context");
ServerHttpRequest mutated = request.mutate().contextPath(null).build();
assertThat(mutated.getPath().contextPath().value()).isEmpty();
assertThat(mutated.getPath().pathWithinApplication().value()).isEqualTo("/context/path");
assertThat(mutated.getURI().getRawPath()).isEqualTo("/context/path");
}
@Test
void mutateContextPathWithoutUpdatingPathShouldFail() throws Exception {
ServerHttpRequest request = createRequest("/context/path", "/context");