diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java index 3d6ae019fd39..29d4aab1e40d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java @@ -134,6 +134,7 @@ public MultiValueMap getCookies() { .secure(cookie.isSecure()) .httpOnly(cookie.isHttpOnly()) .sameSite(getSameSite(cookie)) + .partitioned(getPartitioned(cookie)) .build())); return CollectionUtils.unmodifiableMultiValueMap(result); } @@ -145,6 +146,13 @@ public MultiValueMap getCookies() { return null; } + private static boolean getPartitioned(Cookie cookie) { + if (cookie instanceof DefaultCookie defaultCookie) { + return defaultCookie.isPartitioned(); + } + return false; + } + /** * Called by {@link ReactorClientHttpConnector} when a cancellation is detected * but the content has not been subscribed to. If the subscription never diff --git a/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorClientHttpResponseTest.java b/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorClientHttpResponseTest.java new file mode 100644 index 000000000000..41db765bf945 --- /dev/null +++ b/spring-web/src/test/java/org/springframework/http/client/reactive/ReactorClientHttpResponseTest.java @@ -0,0 +1,54 @@ +package org.springframework.http.client.reactive; + +import io.netty.buffer.AdaptiveByteBufAllocator; +import io.netty.handler.codec.http.DefaultHttpHeaders; +import io.netty.handler.codec.http.cookie.Cookie; +import io.netty.handler.codec.http.cookie.DefaultCookie; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.http.ResponseCookie; +import reactor.netty.Connection; +import reactor.netty.NettyOutbound; +import reactor.netty.http.client.HttpClientResponse; + +import java.util.*; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; + +class ReactorClientHttpResponseTest { + private final HttpClientResponse mockResponse = mock(); + + private final DefaultHttpHeaders httpHeaders = mock(); + + private final Connection connection = mock(); + + private final NettyOutbound outbound = mock(); + + private ReactorClientHttpResponse reactorClientHttpResponse; + + + @BeforeEach + void configureMocks() { + given(mockResponse.responseHeaders()).willReturn(httpHeaders); + given(connection.outbound()).willReturn(outbound); + given(outbound.alloc()).willReturn(new AdaptiveByteBufAllocator()); + reactorClientHttpResponse = new ReactorClientHttpResponse(mockResponse, connection); + } + + @Test + void defaultCookies() { + Map> mockCookieMap = new HashMap<>(); + DefaultCookie cookie = new DefaultCookie("foo", "bar"); + cookie.setPartitioned(true); + mockCookieMap.put("foo", Set.of(cookie)); + given(mockResponse.cookies()).willReturn(mockCookieMap); + + Assertions.assertTrue(reactorClientHttpResponse.getCookies().size() == 1 && + reactorClientHttpResponse.getCookies().containsKey("foo")); + ResponseCookie foo = reactorClientHttpResponse.getCookies().getFirst("foo"); + assertThat(foo.isPartitioned()).isSameAs(cookie.isPartitioned()); + } +} \ No newline at end of file