@VisibleForTesting
    void handleResponse(BufferingReadStream responseStream) {
        Buffer responseBody = context.getResponseStream().getContent();
        context.setResponseBody(responseBody);
        context.setResponseBodyTimestamp(System.currentTimeMillis());
        Future<TokenUsage> tokenUsageFuture = collectTokenUsage(responseBody);

        Future<Void> handleResponseFuture = tokenUsageFuture.transform(result -> {
            if (result.failed()) {
                log.warn("Failed to collect token usage. Trace: {}. Span: {}",
                        context.getTraceId(), context.getSpanId(), result.cause());
            }
            return collectResponseAttachments(responseBody);
        });

        handleResponseFuture.onComplete(result -> {
            if (result.failed()) {
                log.warn("Failed to collect attachments from response. Trace: {}. Span: {}",
                        context.getTraceId(), context.getSpanId(), result.cause());
            }
            completeProxyResponse(responseStream);
        });
    }
Called when proxy sent response from the origin to the client.
server/src/main/java/com/epam/aidial/core/server/controller/DeploymentPostController.java