Home / Function/ encode() — netty Function Reference

encode() — netty Function Reference

Architecture documentation for the encode() function in SpdyHttpEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9aa81464_45bd_d2c4_770c_f46f2337d072["encode()"]
  18ed3381_f0b5_3753_fac7_fb58d0f9ddbb["SpdyHttpEncoder"]
  9aa81464_45bd_d2c4_770c_f46f2337d072 -->|defined in| 18ed3381_f0b5_3753_fac7_fb58d0f9ddbb
  4b3a9241_a033_6042_cea3_ac272e0a6928["isLast()"]
  9aa81464_45bd_d2c4_770c_f46f2337d072 -->|calls| 4b3a9241_a033_6042_cea3_ac272e0a6928
  style 9aa81464_45bd_d2c4_770c_f46f2337d072 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java lines 154–216

    @Override
    protected void encode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception {

        boolean valid = false;
        boolean last = false;

        if (msg instanceof HttpRequest) {

            HttpRequest httpRequest = (HttpRequest) msg;
            SpdySynStreamFrame spdySynStreamFrame = createSynStreamFrame(httpRequest);
            out.add(spdySynStreamFrame);

            last = spdySynStreamFrame.isLast() || spdySynStreamFrame.isUnidirectional();
            valid = true;
        }
        if (msg instanceof HttpResponse) {

            HttpResponse httpResponse = (HttpResponse) msg;
            SpdyHeadersFrame spdyHeadersFrame = createHeadersFrame(httpResponse);
            out.add(spdyHeadersFrame);

            last = spdyHeadersFrame.isLast();
            valid = true;
        }
        if (msg instanceof HttpContent && !last) {

            HttpContent chunk = (HttpContent) msg;

            chunk.content().retain();
            SpdyDataFrame spdyDataFrame = new DefaultSpdyDataFrame(currentStreamId, chunk.content());
            if (chunk instanceof LastHttpContent) {
                LastHttpContent trailer = (LastHttpContent) chunk;
                HttpHeaders trailers = trailer.trailingHeaders();
                if (trailers.isEmpty()) {
                    spdyDataFrame.setLast(true);
                    out.add(spdyDataFrame);
                } else {
                    // Create SPDY HEADERS frame out of trailers
                    SpdyHeadersFrame spdyHeadersFrame = new DefaultSpdyHeadersFrame(currentStreamId, validateHeaders);
                    spdyHeadersFrame.setLast(true);
                    Iterator<Entry<CharSequence, CharSequence>> itr = trailers.iteratorCharSequence();
                    while (itr.hasNext()) {
                        Map.Entry<CharSequence, CharSequence> entry = itr.next();
                        final CharSequence headerName =
                                headersToLowerCase ? AsciiString.of(entry.getKey()).toLowerCase() : entry.getKey();
                        spdyHeadersFrame.headers().add(headerName, entry.getValue());
                    }

                    // Write DATA frame and append HEADERS frame
                    out.add(spdyDataFrame);
                    out.add(spdyHeadersFrame);
                }
            } else {
                out.add(spdyDataFrame);
            }

            valid = true;
        }

        if (!valid) {
            throw new UnsupportedMessageTypeException(msg);
        }
    }

Domain

Subdomains

Calls

Frequently Asked Questions

What does encode() do?
encode() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java.
Where is encode() defined?
encode() is defined in codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyHttpEncoder.java at line 154.
What does encode() call?
encode() calls 1 function(s): isLast.

Analyze Your Own Codebase

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

Try Supermodel Free