channelRead0() — netty Function Reference
Architecture documentation for the channelRead0() function in HttpUploadServerHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 98681448_b82b_1b97_25a8_c44670111876["channelRead0()"] 15610e19_8d3a_d230_9604_65cc0397e9e9["HttpUploadServerHandler"] 98681448_b82b_1b97_25a8_c44670111876 -->|defined in| 15610e19_8d3a_d230_9604_65cc0397e9e9 d1e50d33_7f97_e02f_a49f_0d6fd3b1bffa["writeMenu()"] 98681448_b82b_1b97_25a8_c44670111876 -->|calls| d1e50d33_7f97_e02f_a49f_0d6fd3b1bffa 249432b1_eedb_b971_9cab_31fe7c2b63bd["writeResponse()"] 98681448_b82b_1b97_25a8_c44670111876 -->|calls| 249432b1_eedb_b971_9cab_31fe7c2b63bd d050c74a_76ad_11ea_4f73_932ffdd57807["readHttpDataChunkByChunk()"] 98681448_b82b_1b97_25a8_c44670111876 -->|calls| d050c74a_76ad_11ea_4f73_932ffdd57807 923cd3c6_0e58_e3f0_61cd_79174fab9b80["reset()"] 98681448_b82b_1b97_25a8_c44670111876 -->|calls| 923cd3c6_0e58_e3f0_61cd_79174fab9b80 style 98681448_b82b_1b97_25a8_c44670111876 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java lines 98–199
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
if (msg instanceof HttpRequest) {
HttpRequest request = this.request = (HttpRequest) msg;
URI uri = new URI(request.uri());
if (!uri.getPath().startsWith("/form")) {
// Write Menu
writeMenu(ctx);
return;
}
responseContent.setLength(0);
responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
responseContent.append("===================================\r\n");
responseContent.append("VERSION: " + request.protocolVersion().text() + "\r\n");
responseContent.append("REQUEST_URI: " + request.uri() + "\r\n\r\n");
responseContent.append("\r\n\r\n");
// new getMethod
for (Entry<String, String> entry : request.headers()) {
responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
}
responseContent.append("\r\n\r\n");
// new getMethod
Set<Cookie> cookies;
String value = request.headers().get(HttpHeaderNames.COOKIE);
if (value == null) {
cookies = Collections.emptySet();
} else {
cookies = ServerCookieDecoder.STRICT.decode(value);
}
for (Cookie cookie : cookies) {
responseContent.append("COOKIE: " + cookie + "\r\n");
}
responseContent.append("\r\n\r\n");
QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri());
Map<String, List<String>> uriAttributes = decoderQuery.parameters();
for (Entry<String, List<String>> attr: uriAttributes.entrySet()) {
for (String attrVal: attr.getValue()) {
responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");
}
}
responseContent.append("\r\n\r\n");
// if GET Method: should not try to create an HttpPostRequestDecoder
if (HttpMethod.GET.equals(request.method())) {
// GET Method: should not try to create an HttpPostRequestDecoder
// So stop here
responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
// Not now: LastHttpContent will be sent writeResponse(ctx.channel());
return;
}
try {
decoder = new HttpPostRequestDecoder(factory, request);
} catch (ErrorDataDecoderException e1) {
e1.printStackTrace();
responseContent.append(e1.getMessage());
writeResponse(ctx.channel(), true);
return;
}
boolean readingChunks = HttpUtil.isTransferEncodingChunked(request);
responseContent.append("Is Chunked: " + readingChunks + "\r\n");
responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
if (readingChunks) {
// Chunk version
responseContent.append("Chunks: ");
}
}
// check if the decoder was constructed before
// if not it handles the form get
if (decoder != null) {
if (msg instanceof HttpContent) {
// New chunk is received
HttpContent chunk = (HttpContent) msg;
try {
decoder.offer(chunk);
Domain
Subdomains
Source
Frequently Asked Questions
What does channelRead0() do?
channelRead0() is a function in the netty codebase, defined in example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java.
Where is channelRead0() defined?
channelRead0() is defined in example/src/main/java/io/netty/example/http/upload/HttpUploadServerHandler.java at line 98.
What does channelRead0() call?
channelRead0() calls 4 function(s): readHttpDataChunkByChunk, reset, writeMenu, writeResponse.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free