Home / Class/ ClientHandler Class — netty Architecture

ClientHandler Class — netty Architecture

Architecture documentation for the ClientHandler class in DefaultHttp2PushPromiseFrameTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4f26c93c_0586_84ae_b8d6_c3389b56672c["ClientHandler"]
  5b2ea007_15cc_23b9_2b36_e512a7fce7c3["DefaultHttp2PushPromiseFrameTest.java"]
  4f26c93c_0586_84ae_b8d6_c3389b56672c -->|defined in| 5b2ea007_15cc_23b9_2b36_e512a7fce7c3
  4553c145_ff1d_9ffb_0177_b667cac9b44f["channelActive()"]
  4f26c93c_0586_84ae_b8d6_c3389b56672c -->|method| 4553c145_ff1d_9ffb_0177_b667cac9b44f
  aeb65ee4_74e7_1854_a564_7bb01e9c4ce9["write()"]
  4f26c93c_0586_84ae_b8d6_c3389b56672c -->|method| aeb65ee4_74e7_1854_a564_7bb01e9c4ce9
  d36dda17_5603_2e74_6899_d09d92687d79["channelRead()"]
  4f26c93c_0586_84ae_b8d6_c3389b56672c -->|method| d36dda17_5603_2e74_6899_d09d92687d79

Relationship Graph

Source Code

codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java lines 165–232

    private static final class ClientHandler extends Http2ChannelDuplexHandler {

        private final CountDownLatch latch = new CountDownLatch(1);
        private volatile ChannelHandlerContext ctx;

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws InterruptedException {
            this.ctx = ctx;
            latch.countDown();
        }

        void write() throws InterruptedException {
            latch.await();
            Http2Headers http2Headers = new DefaultHttp2Headers();
            http2Headers.path("/")
                    .authority("localhost")
                    .method("GET")
                    .scheme("https");

            Http2HeadersFrame headersFrame = new DefaultHttp2HeadersFrame(http2Headers, true);
            headersFrame.stream(newStream());
            ctx.writeAndFlush(headersFrame);
        }

        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) {

            if (msg instanceof Http2PushPromiseFrame) {
                Http2PushPromiseFrame pushPromiseFrame = (Http2PushPromiseFrame) msg;

                assertEquals("/meow", pushPromiseFrame.http2Headers().path().toString());
                assertEquals("GET", pushPromiseFrame.http2Headers().method().toString());
                assertEquals("https", pushPromiseFrame.http2Headers().scheme().toString());
                assertEquals("localhost:5555", pushPromiseFrame.http2Headers().authority().toString());

                Http2PriorityFrame priorityFrame = new DefaultHttp2PriorityFrame(pushPromiseFrame.stream().id(),
                        Http2CodecUtil.DEFAULT_PRIORITY_WEIGHT, true);
                priorityFrame.stream(pushPromiseFrame.pushStream());
                ctx.writeAndFlush(priorityFrame);
            } else if (msg instanceof Http2HeadersFrame) {
                Http2HeadersFrame headersFrame = (Http2HeadersFrame) msg;

                if (headersFrame.stream().id() == 3) {
                    assertEquals("200", headersFrame.headers().status().toString());
                    assertEquals("false", headersFrame.headers().get("push").toString());
                } else if (headersFrame.stream().id() == 2) {
                    assertEquals("200", headersFrame.headers().status().toString());
                    assertEquals("true", headersFrame.headers().get("push").toString());
                } else {
                    ctx.writeAndFlush(new DefaultHttp2GoAwayFrame(Http2Error.REFUSED_STREAM));
                }
            } else if (msg instanceof Http2DataFrame) {
                Http2DataFrame dataFrame = (Http2DataFrame) msg;

                try {
                    if (dataFrame.stream().id() == 3) {
                        assertEquals("Meow", dataFrame.content().toString(CharsetUtil.UTF_8));
                    } else if (dataFrame.stream().id() == 2) {
                        assertEquals("Meow, I am Pushed via HTTP/2", dataFrame.content().toString(CharsetUtil.UTF_8));
                    } else {
                        ctx.writeAndFlush(new DefaultHttp2GoAwayFrame(Http2Error.REFUSED_STREAM));
                    }
                } finally {
                    ReferenceCountUtil.release(dataFrame);
                }
            }
        }
    }

Frequently Asked Questions

What is the ClientHandler class?
ClientHandler is a class in the netty codebase, defined in codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java.
Where is ClientHandler defined?
ClientHandler is defined in codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2PushPromiseFrameTest.java at line 165.

Analyze Your Own Codebase

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

Try Supermodel Free