1
1
/*
2
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -189,8 +189,11 @@ public HttpClient.Version version() {
189
189
if (obp .isPresent ()) {
190
190
ConsumingSubscriber subscriber = new ConsumingSubscriber ();
191
191
obp .get ().subscribe (subscriber );
192
+ // wait for our subscriber to be completed and get the
193
+ // list of ByteBuffers it received.
194
+ var buffers = subscriber .getBuffers ().join ();
192
195
if (responseBodyBytes == ECHO_SENTINAL ) {
193
- responseBody = subscriber . buffers ;
196
+ responseBody = buffers ;
194
197
}
195
198
}
196
199
@@ -226,6 +229,13 @@ public HttpClient.Version version() {
226
229
*/
227
230
private static class ConsumingSubscriber implements Flow .Subscriber <ByteBuffer > {
228
231
final List <ByteBuffer > buffers = Collections .synchronizedList (new ArrayList <>());
232
+ // A CompletableFuture that will be completed with a list of ByteBuffers that the
233
+ // ConsumingSubscriber has consumed.
234
+ final CompletableFuture <List <ByteBuffer >> consumed = new CompletableFuture <>();
235
+
236
+ public final CompletableFuture <List <ByteBuffer >> getBuffers () {
237
+ return consumed ;
238
+ }
229
239
230
240
@ Override
231
241
public void onSubscribe (Flow .Subscription subscription ) {
@@ -236,8 +246,8 @@ public void onSubscribe(Flow.Subscription subscription) {
236
246
buffers .add (item .duplicate ());
237
247
}
238
248
239
- @ Override public void onError (Throwable throwable ) { assert false : "Unexpected" ; }
249
+ @ Override public void onError (Throwable throwable ) { consumed . completeExceptionally ( throwable ) ; }
240
250
241
- @ Override public void onComplete () { /* do nothing */ }
251
+ @ Override public void onComplete () { consumed . complete ( buffers . stream (). toList ()); }
242
252
}
243
253
}
0 commit comments