Home / Function/ write() — netty Function Reference

write() — netty Function Reference

Architecture documentation for the write() function in Http3FrameToHttpObjectCodec.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  76b7e29c_b468_1120_b8de_3bb312465670["write()"]
  89b6ef44_7b8b_bd87_22f1_6b099293d25d["Http3FrameToHttpObjectCodec"]
  76b7e29c_b468_1120_b8de_3bb312465670 -->|defined in| 89b6ef44_7b8b_bd87_22f1_6b099293d25d
  1732bdd0_e0f1_4455_0b06_9b07872f84d8["ChannelPromise()"]
  1732bdd0_e0f1_4455_0b06_9b07872f84d8 -->|calls| 76b7e29c_b468_1120_b8de_3bb312465670
  style 76b7e29c_b468_1120_b8de_3bb312465670 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameToHttpObjectCodec.java lines 135–215

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        if (!(msg instanceof HttpObject)) {
            throw new UnsupportedMessageTypeException(msg, HttpObject.class);
        }
        // 100-continue is typically a FullHttpResponse, but the decoded
        // Http3HeadersFrame should not handles as a end of stream.
        if (msg instanceof HttpResponse) {
            final HttpResponse res = (HttpResponse) msg;
            if (res.status().equals(HttpResponseStatus.CONTINUE)) {
                if (res instanceof FullHttpResponse) {
                    final Http3Headers headers = toHttp3Headers(res);
                    ctx.write(new DefaultHttp3HeadersFrame(headers), promise);
                    ((FullHttpResponse) res).release();
                    return;
                } else {
                    throw new EncoderException(
                            HttpResponseStatus.CONTINUE + " must be a FullHttpResponse");
                }
            }
        }

        // this combiner is created lazily if we need multiple write calls
        PromiseCombiner combiner = null;
        // With the last content, *if* we write anything here, we need to wait for that write to complete before
        // closing. To do that, we need to unvoid the promise. So if we write anything *and* this is the last message
        // we will unvoid.
        boolean isLast = msg instanceof LastHttpContent;

        if (msg instanceof HttpMessage) {
            Http3Headers headers = toHttp3Headers((HttpMessage) msg);
            DefaultHttp3HeadersFrame frame = new DefaultHttp3HeadersFrame(headers);

            if (msg instanceof HttpContent && (!promise.isVoid() || isLast)) {
                combiner = new PromiseCombiner(ctx.executor());
            }
            promise = writeWithOptionalCombiner(ctx, frame, promise, combiner, isLast);
        }

        if (isLast) {
            LastHttpContent last = (LastHttpContent) msg;
            try {
                boolean readable = last.content().isReadable();
                boolean hasTrailers = !last.trailingHeaders().isEmpty();

                if (combiner == null && readable && hasTrailers && !promise.isVoid()) {
                    combiner = new PromiseCombiner(ctx.executor());
                }

                if (readable) {
                    promise = writeWithOptionalCombiner(
                            ctx, new DefaultHttp3DataFrame(last.content().retain()), promise, combiner, true);
                }
                if (hasTrailers) {
                    Http3Headers headers = HttpConversionUtil.toHttp3Headers(last.trailingHeaders(), validateHeaders);
                    promise = writeWithOptionalCombiner(ctx,
                            new DefaultHttp3HeadersFrame(headers), promise, combiner, true);
                } else if (!readable) {
                    if (combiner == null) {
                        // We only need to write something if there was no write before.
                        promise = writeWithOptionalCombiner(
                                ctx, new DefaultHttp3DataFrame(last.content().retain()), promise, combiner, true);
                    }
                }
                // The shutdown is always done via the listener to ensure previous written data is correctly drained
                // before QuicStreamChannel.shutdownOutput() is called. Missing to do so might cause previous queued
                // data to be failed with a ClosedChannelException.
                promise = promise.unvoid().addListener(QuicStreamChannel.SHUTDOWN_OUTPUT);
            } finally {
                // Release LastHttpContent, we retain the content if we need it.
                last.release();
            }
        } else if (msg instanceof HttpContent) {
            promise = writeWithOptionalCombiner(ctx,
                    new DefaultHttp3DataFrame(((HttpContent) msg).content()), promise, combiner, false);
        }

        if (combiner != null) {
            combiner.finish(promise);
        }
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does write() do?
write() is a function in the netty codebase, defined in codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameToHttpObjectCodec.java.
Where is write() defined?
write() is defined in codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameToHttpObjectCodec.java at line 135.
What calls write()?
write() is called by 1 function(s): ChannelPromise.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free