private void performWrite(WriteTask task) {
            try {
                synchronized (monitor) {
                    if (invalidated) {
                        task.handler.failed(new IllegalStateException("Content channel is invalidated"));
                        return;
                    }
                    if (!jettyResponse.isCommitted()) {
                        jettyResponse.setStatus(jdiscResponse.getStatus());
                        var jettyHeaders = jettyResponse.getHeaders();
                        jdiscResponse.headers().forEach((name, values) -> {
                            values.stream()
                                    .filter(Objects::nonNull)
                                    .forEach(value -> jettyHeaders.add(name, value));
                        });
                        if (jettyHeaders.get(HttpHeader.CONTENT_TYPE) == null) {
                            jettyHeaders.add(HttpHeader.CONTENT_TYPE, "text/plain;charset=utf-8");
                        }
                        jettyRequest.setAttribute(MetricAggregatingRequestLog.requestTypeAttribute,
                                jdiscResponse.getRequestType());
                    }
                }

                canWrite = false;
                jettyResponse.write(task.buf == null, Objects.requireNonNullElse(task.buf, EMPTY_BUFFER), new Callback() {
                    @Override
                    public void succeeded() {
                        if (task.buf == null) responseCompletion.complete(null);
                        completeAndFinishTask(task.handler, CompletionHandler::completed);
                        if (task.buf != null) metricReporter.successfulWrite(task.buf.remaining());
                    }

                    @Override
                    public void failed(Throwable x) {
                        responseCompletion.completeExceptionally(x);
                        completeAndFinishTask(task.handler, h -> h.failed(x));
                        metricReporter.failedWrite();
                    }
                });
            } catch (Throwable t) {
                responseCompletion.completeExceptionally(t);
                completeAndFinishTask(task.handler, h -> h.failed(t));
                metricReporter.failedWrite();
            }
        }
A {@link ResponseHandler} that writes the response to Jetty ({@link org.eclipse.jetty.server.Response}).

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