Skip to content

Commit 0a95cea

Browse files
committed
Return as soon as the stream starts if there is a payload in sync http client
1 parent c92fae3 commit 0a95cea

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/loader/ClasspathSdkHttpServiceProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ final class ClasspathSdkHttpServiceProvider<T> implements SdkHttpServiceProvider
6767

6868
@Override
6969
public Optional<T> loadService() {
70-
Queue<T> impls = new PriorityQueue<>(Comparator.comparingInt(o -> httpServicesPriority.getOrDefault(o.getClass().getName(),
71-
Integer.MAX_VALUE)));
70+
Queue<T> impls = new PriorityQueue<>(
71+
Comparator.comparingInt(o -> httpServicesPriority.getOrDefault(o.getClass().getName(),
72+
Integer.MAX_VALUE)));
7273
Iterable<T> iterable = () -> serviceLoader.loadServices(serviceClass);
7374
iterable.forEach(impl -> impls.add(impl));
7475

http-clients/aws-crt-client/src/main/java/software/amazon/awssdk/http/crt/internal/response/InputStreamAdaptingHttpStreamResponseHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public int onResponseBody(HttpStream stream, byte[] bodyBytesIn) {
6969
if (inputStreamSubscriber == null) {
7070
inputStreamSubscriber = new InputStreamSubscriber();
7171
simplePublisher.subscribe(inputStreamSubscriber);
72+
// For response with a payload, we need to complete the future here to allow downstream to retrieve the data from
73+
// the stream directly.
7274
responseBuilder.content(AbortableInputStream.create(inputStreamSubscriber));
75+
requestCompletionFuture.complete(responseBuilder.build());
7376
}
7477

7578
CompletableFuture<Void> writeFuture = simplePublisher.send(ByteBuffer.wrap(bodyBytesIn));
@@ -123,6 +126,8 @@ private void onSuccessfulResponseComplete(HttpStream stream) {
123126
crtConn.shutdown();
124127
}
125128

129+
// For response without a payload, for example, S3 PutObjectResponse, we need to complete the future
130+
// in onResponseComplete callback since onResponseBody will never be invoked.
126131
requestCompletionFuture.complete(responseBuilder.build());
127132
simplePublisher.complete();
128133
crtConn.close();

0 commit comments

Comments
 (0)