Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ServerHttpRequest.Builder path(String path) {
}

@Override
public ServerHttpRequest.Builder contextPath(String contextPath) {
public ServerHttpRequest.Builder contextPath(@Nullable String contextPath) {
this.contextPath = contextPath;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ interface Builder {
* contextPath} and it must match the start of the path of the URI of
* the request. That means changing the contextPath, implies also
* changing the path via {@link #path(String)}.
* <p>A {@code null} value is treated the same as an empty string and
* results in an empty context path.
*/
Builder contextPath(String contextPath);
Builder contextPath(@Nullable String contextPath);


/**
* Set or override the specified header values under the given name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ private ServerHttpRequest createMockRequest(HttpHeaders originalHeaders) {
return mock;
}

@org.junit.jupiter.api.Test
void contextPathNullable() {
ServerHttpRequest request = MockServerHttpRequest.get("/foo/bar").contextPath("/foo").build();
assertThat(request.getPath().contextPath().value()).isEqualTo("/foo");

ServerHttpRequest mutated = request.mutate().contextPath(null).build();
assertThat(mutated.getPath().contextPath().value()).isEmpty();
}

static Arguments initHeader(String description, MultiValueMap<String, String> headerMap) {
headerMap.add("CaseInsensitive", "unmodified");
return argumentSet(description, headerMap, true);
Expand All @@ -111,3 +120,4 @@ static Stream<Arguments> headers() {
}

}