decode() — netty Function Reference
Architecture documentation for the decode() function in HttpClientUpgradeHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9d58037d_586e_ddf3_d949_447c40752f74["decode()"] 4e189e6a_8380_a786_56f2_e292de03b066["HttpClientUpgradeHandler"] 9d58037d_586e_ddf3_d949_447c40752f74 -->|defined in| 4e189e6a_8380_a786_56f2_e292de03b066 68cbc489_4c93_02e4_be2a_4026606c980c["removeThisHandler()"] 9d58037d_586e_ddf3_d949_447c40752f74 -->|calls| 68cbc489_4c93_02e4_be2a_4026606c980c style 9d58037d_586e_ddf3_d949_447c40752f74 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java lines 187–258
@Override
protected void decode(ChannelHandlerContext ctx, HttpObject msg, List<Object> out)
throws Exception {
FullHttpResponse response = null;
try {
if (currentUpgradeEvent != UpgradeEvent.UPGRADE_ISSUED) {
throw new IllegalStateException("Read HTTP response without requesting protocol switch");
}
if (msg instanceof HttpResponse) {
HttpResponse rep = (HttpResponse) msg;
if (!SWITCHING_PROTOCOLS.equals(rep.status())) {
// The server does not support the requested protocol, just remove this handler
// and continue processing HTTP.
// NOTE: not releasing the response since we're letting it propagate to the
// next handler.
currentUpgradeEvent = null;
ctx.fireUserEventTriggered(UpgradeEvent.UPGRADE_REJECTED);
removeThisHandler(ctx);
ctx.fireChannelRead(msg);
return;
}
}
if (msg instanceof FullHttpResponse) {
response = (FullHttpResponse) msg;
// Need to retain since the base class will release after returning from this method.
response.retain();
out.add(response);
} else {
// Call the base class to handle the aggregation of the full request.
super.decode(ctx, msg, out);
if (out.isEmpty()) {
// The full request hasn't been created yet, still awaiting more data.
return;
}
assert out.size() == 1;
response = (FullHttpResponse) out.get(0);
}
CharSequence upgradeHeader = response.headers().get(HttpHeaderNames.UPGRADE);
if (upgradeHeader != null && !AsciiString.contentEqualsIgnoreCase(upgradeCodec.protocol(), upgradeHeader)) {
throw new IllegalStateException(
"Switching Protocols response with unexpected UPGRADE protocol: " + upgradeHeader);
}
// Upgrade to the new protocol.
sourceCodec.prepareUpgradeFrom(ctx);
upgradeCodec.upgradeTo(ctx, response);
// Let's set currentUpgradeEvent to UPGRADE_SUCCESSFUL as we will notify the pipeline about the successful
// upgrade now, which might results in a write that needs to be passed through.
currentUpgradeEvent = UpgradeEvent.UPGRADE_SUCCESSFUL;
// Notify that the upgrade to the new protocol completed successfully.
ctx.fireUserEventTriggered(UpgradeEvent.UPGRADE_SUCCESSFUL);
// We guarantee UPGRADE_SUCCESSFUL event will be arrived at the next handler
// before http2 setting frame and http response.
sourceCodec.upgradeFrom(ctx);
// We switched protocols, so we're done with the upgrade response.
// Release it and clear it from the output.
response.release();
out.clear();
removeThisHandler(ctx);
} catch (Throwable t) {
ctx.fireExceptionCaught(t);
removeThisHandler(ctx);
}
}
Domain
Subdomains
Calls
Source
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/HttpClientUpgradeHandler.java.
Where is decode() defined?
decode() is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpClientUpgradeHandler.java at line 187.
What does decode() call?
decode() calls 1 function(s): removeThisHandler.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free