Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed "partitioned" attribute from DefaultCookie of ReactorClientHttpResponse.getCookies #34521

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -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());
}
}