mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
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:
committed by
rstoyanchev
parent
82cf15c60f
commit
8d4208f030
+1
-1
@@ -103,7 +103,7 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServerHttpRequest.Builder contextPath(String contextPath) {
|
public ServerHttpRequest.Builder contextPath(@Nullable String contextPath) {
|
||||||
this.contextPath = contextPath;
|
this.contextPath = contextPath;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -146,8 +146,10 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage
|
|||||||
* contextPath} and it must match the start of the path of the URI of
|
* contextPath} and it must match the start of the path of the URI of
|
||||||
* the request. That means changing the contextPath, implies also
|
* the request. That means changing the contextPath, implies also
|
||||||
* changing the path via {@link #path(String)}.
|
* changing the path via {@link #path(String)}.
|
||||||
|
* <p>The given value may be {@code null} or empty to indicate there
|
||||||
|
* is no context path.
|
||||||
*/
|
*/
|
||||||
Builder contextPath(String contextPath);
|
Builder contextPath(@Nullable String contextPath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set or override the specified header values under the given name.
|
* Set or override the specified header values under the given name.
|
||||||
|
|||||||
+10
@@ -194,6 +194,16 @@ class ServerHttpRequestTests {
|
|||||||
assertThat(mutated.getURI().getRawPath()).isEqualTo("/other/path");
|
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
|
@Test
|
||||||
void mutateContextPathWithoutUpdatingPathShouldFail() throws Exception {
|
void mutateContextPathWithoutUpdatingPathShouldFail() throws Exception {
|
||||||
ServerHttpRequest request = createRequest("/context/path", "/context");
|
ServerHttpRequest request = createRequest("/context/path", "/context");
|
||||||
|
|||||||
Reference in New Issue
Block a user