Fix missing Partitioned cookie support in reactive HTTP clients

This commit adds support for the Partitioned cookie attribute in the
reactive HTTP clients that support this: Reactor and HttpComponents.

Closes gh-34521

Signed-off-by: Rhett CfZhuang <dark.momo985@gmail.com>
[brian.clozel@broadcom.com: rework tests and support HttpComponents]
Signed-off-by: Brian Clozel <brian.clozel@broadcom.com>
This commit is contained in:
Rhett CfZhuang 2025-02-28 23:20:36 +08:00 committed by Brian Clozel
parent d2733cea36
commit 5faf2ed7f4
3 changed files with 30 additions and 1 deletions

View File

@ -90,6 +90,7 @@ class HttpComponentsClientHttpResponse extends AbstractClientHttpResponse {
.maxAge(getMaxAgeSeconds(cookie))
.secure(cookie.isSecure())
.httpOnly(cookie.containsAttribute("httponly"))
.partitioned(cookie.containsAttribute("partitioned"))
.sameSite(cookie.getAttribute("samesite"))
.build());
}

View File

@ -148,6 +148,7 @@ class ReactorClientHttpResponse implements ClientHttpResponse {
.secure(cookie.isSecure())
.httpOnly(cookie.isHttpOnly())
.sameSite(getSameSite(cookie))
.partitioned(getPartitioned(cookie))
.build()));
return CollectionUtils.unmodifiableMultiValueMap(result);
}
@ -160,6 +161,13 @@ class ReactorClientHttpResponse implements ClientHttpResponse {
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

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,6 +41,7 @@ import okhttp3.mockwebserver.RecordedRequest;
import okio.Buffer;
import org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.Test;
@ -201,6 +202,25 @@ class ClientHttpConnectorTests {
.verifyComplete();
}
@ParameterizedConnectorTest
void partitionedCookieSupport(ClientHttpConnector connector) {
Assumptions.assumeFalse(connector instanceof JettyClientHttpConnector, "Jetty client does not support partitioned cookies");
Assumptions.assumeFalse(connector instanceof JdkClientHttpConnector, "JDK client does not support partitioned cookies");
prepareResponse(response -> {
response.setResponseCode(200);
response.addHeader("Set-Cookie", "id=test; Partitioned;");
});
Mono<ClientHttpResponse> futureResponse =
connector.connect(HttpMethod.GET, this.server.url("/").uri(), ReactiveHttpOutputMessage::setComplete);
StepVerifier.create(futureResponse)
.assertNext(response -> {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getCookies().getFirst("id").isPartitioned()).isTrue();
}
)
.verifyComplete();
}
@Test
void disableCookieWithHttpComponents() {
ClientHttpConnector connector = new HttpComponentsClientHttpConnector(