private void processChunks() {
        while (true) {
            var chunk = jettyRequest.read();
            if (chunk instanceof Trailers trailers) {
                log.log(Level.FINE, () -> "Received trailers: " + trailers);
                chunk.release();
                return;
            }
            if (chunk == null) {
                log.log(Level.FINE, () -> "Received no chunk");
                jettyRequest.demand(this::processChunks);
                return;
            }
            // Retry read if failure but not the last chunk
            if (Content.Chunk.isFailure(chunk, false)) {
                log.log(Level.FINE, chunk.getFailure(), () -> "Failed to read non-last chunk");
                jettyRequest.demand(this::processChunks);
                return;
            }
            if (Content.Chunk.isFailure(chunk, true)) {
                log.log(Level.FINE, chunk.getFailure(), () -> "Failed to read last chunk");
                jettyReadCompletion.completeExceptionally(chunk.getFailure());
                return;
            }
            var bytesRemaining = chunk.remaining();
            if (bytesRemaining > 0) {
                bytesRead.addAndGet(bytesRemaining);
                // One for the write() and one for the completion
                numberOfOutstandingUserCalls.addAndGet(2);
                var chunkReleaser = new CompletableFuture<Void>()
                        .whenComplete((result, error) -> chunk.release());
                try {
                    contentChannel.write(chunk.getByteBuffer(), new CompletionHandler() {
                        @Override
                        public void completed() {
                            decrementOutstandingUserCalls();
                            chunkReleaser.complete(null);
                        }

                        @Override
                        public void failed(Throwable t) {
                            jettyReadCompletion.completeExceptionally(t);
                            // Decremented for brevity - completionFuture is already completed with a failure
                            decrementOutstandingUserCalls();
                            chunkReleaser.complete(null);
                            log.log(Level.FINE, t, () -> "Failed to write chunk to content channel");
                        }
                    });
                    metricReporter.successfulWrite(bytesRemaining);
                } catch (Throwable t) {
                    chunkReleaser.complete(null);
                    log.log(Level.FINE, t, () -> "Failed to invoke content channel write");
                    jettyReadCompletion.completeExceptionally(t);
                } finally {
                    decrementOutstandingUserCalls();
                }
            } else {
                chunk.release();
            }
            if (chunk.isLast()) {
                // The last chunk is observed, decrement the initial value
                decrementOutstandingUserCalls();
                return; // EOF
            }
        }
    }
Reads request content from a Jetty {@link Request} and writes it to the {@link ContentChannel}
returned by the {@link com.yahoo.jdisc.handler.RequestHandler}.

@author bjorncs
container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JettyRequestContentReader.java