decode() — netty Function Reference
Architecture documentation for the decode() function in HttpObjectDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb["decode()"] 6c551372_1bb2_fe27_3884_c4cc297c86ae["HttpObjectDecoder"] 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb -->|defined in| 6c551372_1bb2_fe27_3884_c4cc297c86ae c3ede65f_ecbf_6fbd_c4d2_9a1fcb90c682["resetNow()"] 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb -->|calls| c3ede65f_ecbf_6fbd_c4d2_9a1fcb90c682 4c11fc2f_f276_60ad_ba54_107006b2835d["splitInitialLine()"] 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb -->|calls| 4c11fc2f_f276_60ad_ba54_107006b2835d 9a2a7408_2b56_cc19_81fd_eb8bd8a25182["addCurrentMessage()"] 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb -->|calls| 9a2a7408_2b56_cc19_81fd_eb8bd8a25182 e8aadc10_5550_f709_7873_e84704f04e88["isDecodingRequest()"] 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb -->|calls| e8aadc10_5550_f709_7873_e84704f04e88 2b1be95c_cb2c_f7ea_5d2f_cb97065fa253["getChunkSize()"] 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb -->|calls| 2b1be95c_cb2c_f7ea_5d2f_cb97065fa253 style 3a54a7e3_c206_fca7_1bb4_d8176ccd19cb fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java lines 357–557
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
if (resetRequested.get()) {
resetNow();
}
switch (currentState) {
case SKIP_CONTROL_CHARS:
// Fall-through
case READ_INITIAL: try {
ByteBuf line = lineParser.parse(buffer, defaultStrictCRLFCheck);
if (line == null) {
return;
}
final String[] initialLine = splitInitialLine(line);
assert initialLine.length == 3 : "initialLine::length must be 3";
message = createMessage(initialLine);
currentState = State.READ_HEADER;
// fall-through
} catch (Exception e) {
out.add(invalidMessage(message, buffer, e));
return;
}
case READ_HEADER: try {
State nextState = readHeaders(buffer);
if (nextState == null) {
return;
}
currentState = nextState;
switch (nextState) {
case SKIP_CONTROL_CHARS:
// fast-path
// No content is expected.
addCurrentMessage(out);
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
resetNow();
return;
case READ_CHUNK_SIZE:
if (!chunkedSupported) {
throw new IllegalArgumentException("Chunked messages not supported");
}
// Chunked encoding - generate HttpMessage first. HttpChunks will follow.
addCurrentMessage(out);
return;
default:
/*
* RFC 7230, 3.3.3 (https://tools.ietf.org/html/rfc7230#section-3.3.3) states that if a
* request does not have either a transfer-encoding or a content-length header then the message body
* length is 0. However, for a response the body length is the number of octets received prior to the
* server closing the connection. So we treat this as variable length chunked encoding.
*/
if (contentLength == 0 || contentLength == -1 && isDecodingRequest()) {
addCurrentMessage(out);
out.add(LastHttpContent.EMPTY_LAST_CONTENT);
resetNow();
return;
}
assert nextState == State.READ_FIXED_LENGTH_CONTENT ||
nextState == State.READ_VARIABLE_LENGTH_CONTENT;
addCurrentMessage(out);
if (nextState == State.READ_FIXED_LENGTH_CONTENT) {
// chunkSize will be decreased as the READ_FIXED_LENGTH_CONTENT state reads data chunk by chunk.
chunkSize = contentLength;
}
// We return here, this forces decode to be called again where we will decode the content
return;
}
} catch (Exception e) {
out.add(invalidMessage(message, buffer, e));
return;
}
case READ_VARIABLE_LENGTH_CONTENT: {
// Keep reading data as a chunk until the end of connection is reached.
int toRead = Math.min(buffer.readableBytes(), maxChunkSize);
if (toRead > 0) {
ByteBuf content = buffer.readRetainedSlice(toRead);
Domain
Subdomains
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/HttpObjectDecoder.java.
Where is decode() defined?
decode() is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectDecoder.java at line 357.
What does decode() call?
decode() calls 5 function(s): addCurrentMessage, getChunkSize, isDecodingRequest, resetNow, splitInitialLine.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free