-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Previously, using Spring Boot 3.3.7 & Spring Cloud 2023.0.3, it was possible to mutate a request inside of a void method.
For example, simply by calling mutate on an ServerHttpRequest object, it was possible to update the request without reassigning the variable.
In the screenshot below, I am able to mutate the request headers on the original object (request), without reassigning the variable.
However, with the latest Spring Boot 3.4.2 & Spring Cloud 2024.0.0, this is no longer working. Now, it looks like the request object must have it's pointer reassigned.
This seems to have been asked as-well on StackOverflow. However, the suggestion to reassign the variable seems to require unnecessary refactor.
Is this a bug or just something the community will have to deal with?
Here's an example in our application where this ability was previously useful:
POC Code:
@ExtendWith(MockitoExtension.class)
class HeadersUtilTest {
@Test
@DisplayName("Should Add Header to Request")
void shouldAddHeaderToRequest() {
ServerHttpRequest request = MockServerHttpRequest.post("/unit-test").build();
ServerHttpRequest mutated = request.mutate().header("x", "y").build();
boolean worksMutated = mutated.getHeaders().containsKey("x");
assertTrue(worksMutated);
boolean worksOriginal = request.getHeaders().containsKey("x"); // used to work on 3.3.7 , is broken on 3.4.2
assertTrue(worksOriginal);
}


