Home / Function/ decode() — netty Function Reference

decode() — netty Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  71a1fb51_f416_1d4b_7593_4149e6ec5c5d["decode()"]
  9c8c1840_4e39_0876_abe2_bb3ce8067466["HttpServerUpgradeHandler"]
  71a1fb51_f416_1d4b_7593_4149e6ec5c5d -->|defined in| 9c8c1840_4e39_0876_abe2_bb3ce8067466
  facc240a_d60c_c641_9420_a67c114728b0["shouldHandleUpgradeRequest()"]
  71a1fb51_f416_1d4b_7593_4149e6ec5c5d -->|calls| facc240a_d60c_c641_9420_a67c114728b0
  149aae54_88df_d06f_7ef6_3a140cffc9ad["upgrade()"]
  71a1fb51_f416_1d4b_7593_4149e6ec5c5d -->|calls| 149aae54_88df_d06f_7ef6_3a140cffc9ad
  style 71a1fb51_f416_1d4b_7593_4149e6ec5c5d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/HttpServerUpgradeHandler.java lines 272–337

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

        if (!handlingUpgrade) {
            // Not handling an upgrade request yet. Check if we received a new upgrade request.
            if (msg instanceof HttpRequest) {
                HttpRequest req = (HttpRequest) msg;
                if (req.headers().contains(HttpHeaderNames.UPGRADE) &&
                    shouldHandleUpgradeRequest(req)) {
                    handlingUpgrade = true;
                    failedAggregationStart = true; // reset if beginAggregation is called
                } else {
                    if (removeAfterFirstRequest) {
                        // This is not an upgrade request, just remove this handler.
                        ctx.pipeline().remove(this);
                    }
                    ReferenceCountUtil.retain(msg);
                    ctx.fireChannelRead(msg);
                    return;
                }
            } else {
                ReferenceCountUtil.retain(msg);
                ctx.fireChannelRead(msg);
                return;
            }
        }

        FullHttpRequest fullRequest;
        if (msg instanceof FullHttpRequest) {
            fullRequest = (FullHttpRequest) msg;
            ReferenceCountUtil.retain(msg);
            out.add(msg);
        } else {
            // Call the base class to handle the aggregation of the full request.
            super.decode(ctx, msg, out);
            if (out.isEmpty()) {
                if (msg instanceof LastHttpContent || failedAggregationStart) {
                    // request failed to aggregate, try with the next request
                    handlingUpgrade = false;
                    releaseCurrentMessage();
                }

                // The full request hasn't been created yet, still awaiting more data.
                return;
            }

            // Finished aggregating the full request, get it from the output list.
            assert out.size() == 1;
            handlingUpgrade = false;
            fullRequest = (FullHttpRequest) out.get(0);
        }

        if (upgrade(ctx, fullRequest)) {
            // The upgrade was successful, remove the message from the output list
            // so that it's not propagated to the next handler. This request will
            // be propagated as a user event instead.
            out.clear();
        } else if (removeAfterFirstRequest) {
            // We handle the first request and were not able to upgrade, just remove this handler.
            ctx.pipeline().remove(this);
        }

        // The upgrade did not succeed, just allow the full request to propagate to the
        // next handler.
    }

Subdomains

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/HttpServerUpgradeHandler.java.
Where is decode() defined?
decode() is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpServerUpgradeHandler.java at line 272.
What does decode() call?
decode() calls 2 function(s): shouldHandleUpgradeRequest, upgrade.

Analyze Your Own Codebase

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

Try Supermodel Free