Skip to content

Commit

Permalink
Fixed "partitioned" attribute from DefaultCookie of ReactorClientHttp…
Browse files Browse the repository at this point in the history
…Response.getCookies

Signed-off-by: Rhett CfZhuang <[email protected]>
  • Loading branch information
dark2momo committed Feb 28, 2025
1 parent b610711 commit 7d9dc40
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public MultiValueMap<String, ResponseCookie> getCookies() {
.secure(cookie.isSecure())
.httpOnly(cookie.isHttpOnly())
.sameSite(getSameSite(cookie))
.partitioned(getPartitioned(cookie))
.build()));
return CollectionUtils.unmodifiableMultiValueMap(result);
}
Expand All @@ -145,6 +146,13 @@ public MultiValueMap<String, ResponseCookie> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<CharSequence, Set<Cookie>> 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());
}
}

0 comments on commit 7d9dc40

Please sign in to comment.