HelloWorldHttp1Handler Class — netty Architecture
Architecture documentation for the HelloWorldHttp1Handler class in HelloWorldHttp1Handler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 653a7c94_6dfd_89c0_369e_fe695dc47f43["HelloWorldHttp1Handler"] bfd2e1ed_b446_a39b_09bf_40f619674006["HelloWorldHttp1Handler.java"] 653a7c94_6dfd_89c0_369e_fe695dc47f43 -->|defined in| bfd2e1ed_b446_a39b_09bf_40f619674006 0c3fd301_6f30_1707_f132_e93ea865ab5c["HelloWorldHttp1Handler()"] 653a7c94_6dfd_89c0_369e_fe695dc47f43 -->|method| 0c3fd301_6f30_1707_f132_e93ea865ab5c 59fb26e3_d6a1_690c_13d0_0421f708e901["channelRead0()"] 653a7c94_6dfd_89c0_369e_fe695dc47f43 -->|method| 59fb26e3_d6a1_690c_13d0_0421f708e901 cc91e623_a64a_9dc7_29a2_63b88a331ebc["channelReadComplete()"] 653a7c94_6dfd_89c0_369e_fe695dc47f43 -->|method| cc91e623_a64a_9dc7_29a2_63b88a331ebc e38e1407_8e05_f97b_d5f4_68c71a39ad76["exceptionCaught()"] 653a7c94_6dfd_89c0_369e_fe695dc47f43 -->|method| e38e1407_8e05_f97b_d5f4_68c71a39ad76
Relationship Graph
Source Code
example/src/main/java/io/netty/example/http2/helloworld/server/HelloWorldHttp1Handler.java lines 43–87
public class HelloWorldHttp1Handler extends SimpleChannelInboundHandler<FullHttpRequest> {
private final String establishApproach;
public HelloWorldHttp1Handler(String establishApproach) {
this.establishApproach = checkNotNull(establishApproach, "establishApproach");
}
@Override
public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
if (HttpUtil.is100ContinueExpected(req)) {
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE, Unpooled.EMPTY_BUFFER));
}
ByteBuf content = ctx.alloc().buffer();
content.writeBytes(HelloWorldHttp2Handler.RESPONSE_BYTES.duplicate());
ByteBufUtil.writeAscii(content, " - via " + req.protocolVersion() + " (" + establishApproach + ")");
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
boolean keepAlive = HttpUtil.isKeepAlive(req);
if (keepAlive) {
if (req.protocolVersion().equals(HTTP_1_0)) {
response.headers().set(CONNECTION, KEEP_ALIVE);
}
ctx.write(response);
} else {
// Tell the client we're going to close the connection.
response.headers().set(CONNECTION, CLOSE);
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
}
}
@Override
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
ctx.flush();
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
}
Defined In
Source
Frequently Asked Questions
What is the HelloWorldHttp1Handler class?
HelloWorldHttp1Handler is a class in the netty codebase, defined in example/src/main/java/io/netty/example/http2/helloworld/server/HelloWorldHttp1Handler.java.
Where is HelloWorldHttp1Handler defined?
HelloWorldHttp1Handler is defined in example/src/main/java/io/netty/example/http2/helloworld/server/HelloWorldHttp1Handler.java at line 43.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free