private static <U extends AggregatedHttpMessage> CompletableFuture<U> handleAggregation(
            AggregationOptions options, CompletableFuture<?> aggregation) {
        if (!options.preferCached()) {
            throw new IllegalStateException("the stream was aggregated previously. options: " + options);
        }
        if (aggregation == NO_CACHE) {
            throw new IllegalStateException(
                    "the stream was aggregated previously without cache. options: " + options);
        }

        //noinspection unchecked
        return (CompletableFuture<U>) aggregation;
    }
Aggregates an {@link HttpMessage} into an {@link AggregatedHttpMessage} using
the specified {@link AggregationOptions}.

<p>Note that this method is added for internal usage. Therefore, you <strong>must not</strong> override
or call this method if you are not familiar with Armeria's internal implementation.
core/src/main/java/com/linecorp/armeria/common/stream/AggregationSupport.java