diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java index 612da6ec3480..ea3fa56d5fe6 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -106,14 +106,12 @@ public Mono connect(HttpMethod method, URI uri, Function> requestCallback) { HttpClientContext context = this.contextProvider.apply(method, uri); - if (context.getCookieStore() == null) { context.setCookieStore(new BasicCookieStore()); } - HttpComponentsClientHttpRequest request = new HttpComponentsClientHttpRequest(method, uri, - context, this.dataBufferFactory); - + HttpComponentsClientHttpRequest request = + new HttpComponentsClientHttpRequest(method, uri, context, this.dataBufferFactory); return requestCallback.apply(request).then(Mono.defer(() -> execute(request, context))); } @@ -123,7 +121,6 @@ private Mono execute(HttpComponentsClientHttpRequest request return Mono.create(sink -> { ReactiveResponseConsumer reactiveResponseConsumer = new ReactiveResponseConsumer(new MonoFutureCallbackAdapter(sink, this.dataBufferFactory, context)); - this.client.execute(requestProducer, reactiveResponseConsumer, context, null); }); } @@ -133,6 +130,7 @@ public void close() throws IOException { this.client.close(); } + private static class MonoFutureCallbackAdapter implements FutureCallback>> { @@ -144,6 +142,7 @@ private static class MonoFutureCallbackAdapter public MonoFutureCallbackAdapter(MonoSink sink, DataBufferFactory dataBufferFactory, HttpClientContext context) { + this.sink = sink; this.dataBufferFactory = dataBufferFactory; this.context = context; @@ -151,19 +150,12 @@ public MonoFutureCallbackAdapter(MonoSink sink, @Override public void completed(Message> result) { - HttpComponentsClientHttpResponse response = - new HttpComponentsClientHttpResponse(this.dataBufferFactory, result, this.context); - this.sink.success(response); + this.sink.success(new HttpComponentsClientHttpResponse(this.dataBufferFactory, result, this.context)); } @Override public void failed(Exception ex) { - Throwable t = ex; - if (t instanceof HttpStreamResetException) { - HttpStreamResetException httpStreamResetException = (HttpStreamResetException) ex; - t = httpStreamResetException.getCause(); - } - this.sink.error(t); + this.sink.error(ex instanceof HttpStreamResetException && ex.getCause() != null ? ex.getCause() : ex); } @Override