Skip to content

Commit

Permalink
Propagate HttpStreamResetException itself if cause is null
Browse files Browse the repository at this point in the history
Closes gh-30245

(cherry picked from commit 8fca258)
  • Loading branch information
jhoeller committed Mar 30, 2023
1 parent 79c5ef8 commit a93382d
Showing 1 changed file with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -106,14 +106,12 @@ public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
Function<? super ClientHttpRequest, Mono<Void>> 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)));
}

Expand All @@ -123,7 +121,6 @@ private Mono<ClientHttpResponse> execute(HttpComponentsClientHttpRequest request
return Mono.create(sink -> {
ReactiveResponseConsumer reactiveResponseConsumer =
new ReactiveResponseConsumer(new MonoFutureCallbackAdapter(sink, this.dataBufferFactory, context));

this.client.execute(requestProducer, reactiveResponseConsumer, context, null);
});
}
Expand All @@ -133,6 +130,7 @@ public void close() throws IOException {
this.client.close();
}


private static class MonoFutureCallbackAdapter
implements FutureCallback<Message<HttpResponse, Publisher<ByteBuffer>>> {

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

public MonoFutureCallbackAdapter(MonoSink<ClientHttpResponse> sink,
DataBufferFactory dataBufferFactory, HttpClientContext context) {

this.sink = sink;
this.dataBufferFactory = dataBufferFactory;
this.context = context;
}

@Override
public void completed(Message<HttpResponse, Publisher<ByteBuffer>> 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
Expand Down

0 comments on commit a93382d

Please sign in to comment.