Skip to content

Commit

Permalink
Fix NullPointerException in HttpComponentsClientHttpResponse
Browse files Browse the repository at this point in the history
Closes gh-34132
  • Loading branch information
sdeleuze committed Dec 23, 2024
1 parent 5ce5647 commit 69b74d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ private static MultiValueMap<String, ResponseCookie> adaptCookies(
LinkedMultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>();

CookieSpec cookieSpec = context.getCookieSpec();
CookieOrigin cookieOrigin = context.getCookieOrigin();
if (cookieSpec == null) {
return result;
}

CookieOrigin cookieOrigin = context.getCookieOrigin();
Iterator<Header> itr = response.headerIterator(HttpHeaders.SET_COOKIE);
while (itr.hasNext()) {
Header header = itr.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
import okhttp3.mockwebserver.MockWebServer;
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.BeforeEach;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -64,6 +66,7 @@
* Tests for {@link ClientHttpConnector} implementations.
* @author Arjen Poutsma
* @author Brian Clozel
* @author Sebastien Deleuze
*/
class ClientHttpConnectorTests {

Expand Down Expand Up @@ -198,6 +201,28 @@ void cookieExpireValueSetAsMaxAge(ClientHttpConnector connector) {
.verifyComplete();
}

@Test
void disableCookieWithHttpComponents() {
ClientHttpConnector connector = new HttpComponentsClientHttpConnector(
HttpAsyncClientBuilder.create().disableCookieManagement().build()
);

prepareResponse(response -> {
response.setResponseCode(200);
response.addHeader("Set-Cookie", "id=test;");
});
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()).isEmpty();
}
)
.verifyComplete();

}

private Buffer randomBody(int size) {
Buffer responseBody = new Buffer();
Random rnd = new Random();
Expand Down

0 comments on commit 69b74d7

Please sign in to comment.