Need help to asynchronously handle the request header in PlayServiceCall before the body is processed


I’m trying to implement a file upload using Lagom 1.3.10 (Java API). As suggested in other topics I used PlayServiceCall and it worked pretty well. The problem appeared when I tried to add an authentication which is implemented as a cross-cutting asynchronous call to another Lagom service. I did it like in the snippet below:

protected <Request, Response> PlayServiceCall<Request, Response> withAuthenticatedUserAndRawRequest(
          Function<User, Function<Http.RequestHeader, Function<ByteString, Result>>> action, Executor ec) {
    return req -> EssentialAction.of(requestHeader -> {
      final Headers headers = headers(requestHeader);

      Sink<ByteString, CompletionStage<Either<Throwable, ByteStringBuilder>>> sink = Sink.fold(Either.right(ByteString.createBuilder()), (aggr, next) ->
    , sb -> Either.right(sb.append(next)))

      return Accumulator.fromSink(sink).mapFuture(result ->
                      authAndValidationStage(headers).thenApply(tokenValidationResult ->
                                      t -> Results.badRequest(t.getMessage()),
                                      sb -> action.apply(tokenValidationResult.getUser()).apply(requestHeader).apply(sb.result())
              , ec);
// Validates the user (via headers) using an asynchronous call to another Lagom service
protected CompletionStage<TokenValidationResult> authAndValidationStage(Headers headers);

and then to use it:

  public ServiceCall<NotUsed, String> storeData(String id) {
    return withAuthenticatedUserAndRawRequest(user -> rh -> rawRequest -> {
      // store the request raw data, e.g. store in S3 / fs, etc
      return Results.ok("Processed");
    }, executor);

The code above functionally works but the body of the request is accumulated in memory before the user is authenticated, which is a security issue.
If I call the authentication before returning the accumulator then the code doesn’t compile as EssentialAction.of expects RequestHeader -> Accumulator, not RequestHeader -> CompletableState.
Also, I wasn’t able to find the way to compose service calls as suggested in Lagom documentation because HeaderServiceCall is not combined with PlayServiceCall as the later is not a subclass of ServerServiceCall.
Tried to use Accumulator.through(flow) approach but the flow doesn’t seem to be called.

Using Play controller is not an option or at least is not an option for this discussion.

Am I missing something? Are there other options? Is there a recommended way to handle such a scenario?
Thanks in advance!