Home / Class/ HttpNativeServerHandler Class — netty Architecture

HttpNativeServerHandler Class — netty Architecture

Architecture documentation for the HttpNativeServerHandler class in HttpNativeServerHandler.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  f68147b4_a73a_8a4e_31d5_88c68b7d895e["HttpNativeServerHandler"]
  73a6b455_8b43_4824_e1bb_e19086a67efe["HttpNativeServerHandler.java"]
  f68147b4_a73a_8a4e_31d5_88c68b7d895e -->|defined in| 73a6b455_8b43_4824_e1bb_e19086a67efe
  9dd83fb6_7a17_7279_f919_340d43e52e1b["HttpNativeServerHandler()"]
  f68147b4_a73a_8a4e_31d5_88c68b7d895e -->|method| 9dd83fb6_7a17_7279_f919_340d43e52e1b
  440d6060_58ca_67fa_4274_363616dd23d1["channelReadComplete()"]
  f68147b4_a73a_8a4e_31d5_88c68b7d895e -->|method| 440d6060_58ca_67fa_4274_363616dd23d1
  975b8e0d_534b_6923_462b_cc8bdd754e3c["channelRead0()"]
  f68147b4_a73a_8a4e_31d5_88c68b7d895e -->|method| 975b8e0d_534b_6923_462b_cc8bdd754e3c
  fa057ed0_a931_313f_7d12_ca1c50c10571["exceptionCaught()"]
  f68147b4_a73a_8a4e_31d5_88c68b7d895e -->|method| fa057ed0_a931_313f_7d12_ca1c50c10571

Relationship Graph

Source Code

testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServerHandler.java lines 35–76

public class HttpNativeServerHandler extends SimpleChannelInboundHandler<HttpObject> {
    private static final byte[] CONTENT = { 'H', 'e', 'l', 'l', 'o', ' ', 'N', 'a', 't', 'i', 'v', 'e' };

    private static final AsciiString KEEP_ALIVE = AsciiString.cached("keep-alive");

    private final CompletableFuture<Void> httpRequestFuture;

    public HttpNativeServerHandler(CompletableFuture<Void> httpRequestFuture) {
        this.httpRequestFuture = httpRequestFuture;
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) {
        ctx.flush();
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
        if (msg instanceof HttpRequest) {
            HttpRequest req = (HttpRequest) msg;

            boolean keepAlive = HttpUtil.isKeepAlive(req);
            FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT));
            response.headers().set(CONTENT_TYPE, "text/plain");
            response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
            httpRequestFuture.complete(null);
            if (!keepAlive) {
                ctx.write(response).addListener(ChannelFutureListener.CLOSE);
            } else {
                response.headers().set(CONNECTION, KEEP_ALIVE);
                ctx.write(response);
            }
        }
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
        httpRequestFuture.completeExceptionally(cause);
        cause.printStackTrace();
        ctx.close();
    }
}

Frequently Asked Questions

What is the HttpNativeServerHandler class?
HttpNativeServerHandler is a class in the netty codebase, defined in testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServerHandler.java.
Where is HttpNativeServerHandler defined?
HttpNativeServerHandler is defined in testsuite-native-image/src/main/java/io/netty/testsuite/svm/HttpNativeServerHandler.java at line 35.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free