/** * Handler async response body with body subscriber. * * @param bodySubscriber the body subscriber. * @param <T> the body type returned by body handler * @return the response future */ public <T> CompletableFuture<Response<T>> handle(BodySubscriber<T> bodySubscriber) { requireNonNull(bodySubscriber); return handle((charset, ri) -> { ri.body().subscribe(bodySubscriber); return bodySubscriber.getBody().toCompletableFuture(); }); }
/** * Treat the response body as String. * * @return the response Future */ public CompletableFuture<Response<String>> toTextResponse() { return handle((charset, ri) -> { var bodySubscriber = BodySubscribers.ofString(charset.get()); ri.body().subscribe(bodySubscriber); return bodySubscriber.getBody().toCompletableFuture(); }); }