11/*
2- * Copyright (c) 2018, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2018, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -209,8 +209,11 @@ public HttpClient.Version version() {
209209 if (obp .isPresent ()) {
210210 ConsumingSubscriber subscriber = new ConsumingSubscriber ();
211211 obp .get ().subscribe (subscriber );
212+ // wait for our subscriber to be completed and get the
213+ // list of ByteBuffers it received.
214+ var buffers = subscriber .getBuffers ().join ();
212215 if (responseBodyBytes == ECHO_SENTINAL ) {
213- responseBody = subscriber . buffers ;
216+ responseBody = buffers ;
214217 }
215218 }
216219
@@ -246,6 +249,13 @@ public HttpClient.Version version() {
246249 */
247250 private static class ConsumingSubscriber implements Flow .Subscriber <ByteBuffer > {
248251 final List <ByteBuffer > buffers = Collections .synchronizedList (new ArrayList <>());
252+ // A CompletableFuture that will be completed with a list of ByteBuffers that the
253+ // ConsumingSubscriber has consumed.
254+ final CompletableFuture <List <ByteBuffer >> consumed = new CompletableFuture <>();
255+
256+ public final CompletableFuture <List <ByteBuffer >> getBuffers () {
257+ return consumed ;
258+ }
249259
250260 @ Override
251261 public void onSubscribe (Flow .Subscription subscription ) {
@@ -256,9 +266,9 @@ public void onSubscribe(Flow.Subscription subscription) {
256266 buffers .add (item .duplicate ());
257267 }
258268
259- @ Override public void onError (Throwable throwable ) { assert false : "Unexpected" ; }
269+ @ Override public void onError (Throwable throwable ) { consumed . completeExceptionally ( throwable ) ; }
260270
261- @ Override public void onComplete () { /* do nothing */ }
271+ @ Override public void onComplete () { consumed . complete ( buffers . stream (). toList ()); }
262272 }
263273
264274 @ Override
0 commit comments