HttpContentDecoder Class — netty Architecture
Architecture documentation for the HttpContentDecoder class in HttpContentDecoder.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD e696bba4_4c61_8bf9_ba74_cc1ca08d7d78["HttpContentDecoder"] b8280e46_90a7_c2ed_4ae7_21e99e1628e2["HttpContentDecoder.java"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|defined in| b8280e46_90a7_c2ed_4ae7_21e99e1628e2 e2abc5a7_f00f_83a5_1312_393b0713ace6["HttpContentDecoder()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| e2abc5a7_f00f_83a5_1312_393b0713ace6 56833c8e_ea43_7960_f859_0a05602dbeb8["decode()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| 56833c8e_ea43_7960_f859_0a05602dbeb8 dbcabd65_3a2f_0f5d_7b33_d7f94d5db2cf["channelReadComplete()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| dbcabd65_3a2f_0f5d_7b33_d7f94d5db2cf 9ff30e19_ca09_008f_1643_9f2dadcdf4c8["EmbeddedChannel()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| 9ff30e19_ca09_008f_1643_9f2dadcdf4c8 f910a1a2_7616_2dc3_d2af_4ff23f45fec8["String()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| f910a1a2_7616_2dc3_d2af_4ff23f45fec8 e6b789af_ce46_e60b_4f5c_42b90b76ecfd["handlerRemoved()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| e6b789af_ce46_e60b_4f5c_42b90b76ecfd 1fea666a_699d_47b5_3b21_94ab703b4e7e["channelInactive()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| 1fea666a_699d_47b5_3b21_94ab703b4e7e 46e4b55a_2cd3_5a52_e061_83692a2da719["handlerAdded()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| 46e4b55a_2cd3_5a52_e061_83692a2da719 97339131_51aa_8600_4baf_d0670bc671ac["cleanup()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| 97339131_51aa_8600_4baf_d0670bc671ac 06dda8d9_c8b7_bc20_fefe_a9a6b875c595["cleanupSafely()"] e696bba4_4c61_8bf9_ba74_cc1ca08d7d78 -->|method| 06dda8d9_c8b7_bc20_fefe_a9a6b875c595
Relationship Graph
Source Code
codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecoder.java lines 48–296
public abstract class HttpContentDecoder extends MessageToMessageDecoder<HttpObject> {
static final String IDENTITY = HttpHeaderValues.IDENTITY.toString();
protected ChannelHandlerContext ctx;
private EmbeddedChannel decoder;
private boolean continueResponse;
private boolean needRead = true;
private ByteBufForwarder forwarder;
public HttpContentDecoder() {
super(HttpObject.class);
}
@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
Source
Frequently Asked Questions
What is the HttpContentDecoder class?
HttpContentDecoder is a class in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecoder.java.
Where is HttpContentDecoder defined?
HttpContentDecoder is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecoder.java at line 48.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free