Skip to content

Commit a93382d

Browse files
committed
Propagate HttpStreamResetException itself if cause is null
Closes gh-30245 (cherry picked from commit 8fca258)
1 parent 79c5ef8 commit a93382d

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpConnector.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -106,14 +106,12 @@ public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
106106
Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
107107

108108
HttpClientContext context = this.contextProvider.apply(method, uri);
109-
110109
if (context.getCookieStore() == null) {
111110
context.setCookieStore(new BasicCookieStore());
112111
}
113112

114-
HttpComponentsClientHttpRequest request = new HttpComponentsClientHttpRequest(method, uri,
115-
context, this.dataBufferFactory);
116-
113+
HttpComponentsClientHttpRequest request =
114+
new HttpComponentsClientHttpRequest(method, uri, context, this.dataBufferFactory);
117115
return requestCallback.apply(request).then(Mono.defer(() -> execute(request, context)));
118116
}
119117

@@ -123,7 +121,6 @@ private Mono<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request
123121
return Mono.create(sink -> {
124122
ReactiveResponseConsumer reactiveResponseConsumer =
125123
new ReactiveResponseConsumer(new MonoFutureCallbackAdapter(sink, this.dataBufferFactory, context));
126-
127124
this.client.execute(requestProducer, reactiveResponseConsumer, context, null);
128125
});
129126
}
@@ -133,6 +130,7 @@ public void close() throws IOException {
133130
this.client.close();
134131
}
135132

133+
136134
private static class MonoFutureCallbackAdapter
137135
implements FutureCallback<Message<HttpResponse, Publisher<ByteBuffer>>> {
138136

@@ -144,26 +142,20 @@ private static class MonoFutureCallbackAdapter
144142

145143
public MonoFutureCallbackAdapter(MonoSink<ClientHttpResponse> sink,
146144
DataBufferFactory dataBufferFactory, HttpClientContext context) {
145+
147146
this.sink = sink;
148147
this.dataBufferFactory = dataBufferFactory;
149148
this.context = context;
150149
}
151150

152151
@Override
153152
public void completed(Message<HttpResponse, Publisher<ByteBuffer>> result) {
154-
HttpComponentsClientHttpResponse response =
155-
new HttpComponentsClientHttpResponse(this.dataBufferFactory, result, this.context);
156-
this.sink.success(response);
153+
this.sink.success(new HttpComponentsClientHttpResponse(this.dataBufferFactory, result, this.context));
157154
}
158155

159156
@Override
160157
public void failed(Exception ex) {
161-
Throwable t = ex;
162-
if (t instanceof HttpStreamResetException) {
163-
HttpStreamResetException httpStreamResetException = (HttpStreamResetException) ex;
164-
t = httpStreamResetException.getCause();
165-
}
166-
this.sink.error(t);
158+
this.sink.error(ex instanceof HttpStreamResetException && ex.getCause() != null ? ex.getCause() : ex);
167159
}
168160

169161
@Override

0 commit comments

Comments
 (0)