Home / Function/ decode() — netty Function Reference

decode() — netty Function Reference

Architecture documentation for the decode() function in HttpContentDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  56833c8e_ea43_7960_f859_0a05602dbeb8["decode()"]
  e696bba4_4c61_8bf9_ba74_cc1ca08d7d78["HttpContentDecoder"]
  56833c8e_ea43_7960_f859_0a05602dbeb8 -->|defined in| e696bba4_4c61_8bf9_ba74_cc1ca08d7d78
  97339131_51aa_8600_4baf_d0670bc671ac["cleanup()"]
  56833c8e_ea43_7960_f859_0a05602dbeb8 -->|calls| 97339131_51aa_8600_4baf_d0670bc671ac
  style 56833c8e_ea43_7960_f859_0a05602dbeb8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecoder.java lines 62–192

    @Override
    protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out) throws Exception {
        needRead = true;
        if (msg instanceof HttpResponse && ((HttpResponse) msg).status().code() == 100) {

            if (!(msg instanceof LastHttpContent)) {
                continueResponse = true;
            }
            // 100-continue response must be passed through.
            needRead = false;
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
            return;
        }

        if (continueResponse) {
            if (msg instanceof LastHttpContent) {
                continueResponse = false;
            }
            // 100-continue response must be passed through.
            needRead = false;
            ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
            return;
        }

        if (msg instanceof HttpMessage) {
            cleanup();
            final HttpMessage message = (HttpMessage) msg;
            final HttpHeaders headers = message.headers();

            // Determine the content encoding.
            String contentEncoding = headers.get(HttpHeaderNames.CONTENT_ENCODING);
            if (contentEncoding != null) {
                contentEncoding = contentEncoding.trim();
            } else {
                String transferEncoding = headers.get(HttpHeaderNames.TRANSFER_ENCODING);
                if (transferEncoding != null) {
                    int idx = transferEncoding.indexOf(',');
                    if (idx != -1) {
                        contentEncoding = transferEncoding.substring(0, idx).trim();
                    } else {
                        contentEncoding = transferEncoding.trim();
                    }
                } else {
                    contentEncoding = IDENTITY;
                }
            }
            decoder = newContentDecoder(contentEncoding);

            if (decoder == null) {
                if (message instanceof HttpContent) {
                    ((HttpContent) message).retain();
                }
                needRead = false;
                ctx.fireChannelRead(message);
                return;
            }
            decoder.pipeline().addLast(forwarder);
            // Remove content-length header:
            // the correct value can be set only after all chunks are processed/decoded.
            // If buffering is not an issue, add HttpObjectAggregator down the chain, it will set the header.
            // Otherwise, rely on LastHttpContent message.
            if (headers.contains(HttpHeaderNames.CONTENT_LENGTH)) {
                headers.remove(HttpHeaderNames.CONTENT_LENGTH);
                headers.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
            }
            // Either it is already chunked or EOF terminated.
            // See https://github.com/netty/netty/issues/5892

            // set new content encoding,
            CharSequence targetContentEncoding = getTargetContentEncoding(contentEncoding);
            if (HttpHeaderValues.IDENTITY.contentEquals(targetContentEncoding)) {
                // Do NOT set the 'Content-Encoding' header if the target encoding is 'identity'
                // as per: https://tools.ietf.org/html/rfc2616#section-14.11
                headers.remove(HttpHeaderNames.CONTENT_ENCODING);
            } else {
                headers.set(HttpHeaderNames.CONTENT_ENCODING, targetContentEncoding);
            }

            if (message instanceof HttpContent) {
                // If message is a full request or response object (headers + data), don't copy data part into out.
                // Output headers only; data part will be decoded below.

Subdomains

Calls

Frequently Asked Questions

What does decode() do?
decode() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecoder.java.
Where is decode() defined?
decode() is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecoder.java at line 62.
What does decode() call?
decode() calls 1 function(s): cleanup.

Analyze Your Own Codebase

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

Try Supermodel Free