Search in sources :

Example 1 with PriorKnowledgeUpgradeEvent

use of io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent in project netty by netty.

the class CleartextHttp2ServerUpgradeHandlerTest method priorKnowledge.

@Test
public void priorKnowledge() throws Exception {
    setUpServerChannel();
    channel.writeInbound(Http2CodecUtil.connectionPrefaceBuf());
    ByteBuf settingsFrame = settingsFrameBuf();
    assertFalse(channel.writeInbound(settingsFrame));
    assertEquals(1, userEvents.size());
    assertTrue(userEvents.get(0) instanceof PriorKnowledgeUpgradeEvent);
    assertEquals(100, http2ConnectionHandler.connection().local().maxActiveStreams());
    assertEquals(65535, http2ConnectionHandler.connection().local().flowController().initialWindowSize());
    verify(frameListener).onSettingsRead(any(ChannelHandlerContext.class), eq(expectedSettings()));
}
Also used : PriorKnowledgeUpgradeEvent(io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 2 with PriorKnowledgeUpgradeEvent

use of io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent in project netty by netty.

the class CleartextHttp2ServerUpgradeHandlerTest method priorKnowledgeInFragments.

@Test
public void priorKnowledgeInFragments() throws Exception {
    setUpServerChannel();
    ByteBuf connectionPreface = Http2CodecUtil.connectionPrefaceBuf();
    assertFalse(channel.writeInbound(connectionPreface.readBytes(5), connectionPreface));
    ByteBuf settingsFrame = settingsFrameBuf();
    assertFalse(channel.writeInbound(settingsFrame));
    assertEquals(1, userEvents.size());
    assertTrue(userEvents.get(0) instanceof PriorKnowledgeUpgradeEvent);
    assertEquals(100, http2ConnectionHandler.connection().local().maxActiveStreams());
    assertEquals(65535, http2ConnectionHandler.connection().local().flowController().initialWindowSize());
    verify(frameListener).onSettingsRead(any(ChannelHandlerContext.class), eq(expectedSettings()));
}
Also used : PriorKnowledgeUpgradeEvent(io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 3 with PriorKnowledgeUpgradeEvent

use of io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent in project netty by netty.

the class CleartextHttp2ServerUpgradeHandlerTest method usedHttp2MultiplexCodec.

@Test
public void usedHttp2MultiplexCodec() throws Exception {
    final Http2MultiplexCodec http2Codec = new Http2MultiplexCodecBuilder(true, new ChannelInitializer<Channel>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
        }
    }).build();
    UpgradeCodecFactory upgradeCodecFactory = new UpgradeCodecFactory() {

        @Override
        public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
            return new Http2ServerUpgradeCodec(http2Codec);
        }
    };
    http2ConnectionHandler = http2Codec;
    userEvents = new ArrayList<Object>();
    HttpServerCodec httpServerCodec = new HttpServerCodec();
    HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(httpServerCodec, upgradeCodecFactory);
    CleartextHttp2ServerUpgradeHandler handler = new CleartextHttp2ServerUpgradeHandler(httpServerCodec, upgradeHandler, http2Codec);
    channel = new EmbeddedChannel(handler, new ChannelInboundHandlerAdapter() {

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            userEvents.add(evt);
        }
    });
    assertFalse(channel.writeInbound(Http2CodecUtil.connectionPrefaceBuf()));
    ByteBuf settingsFrame = settingsFrameBuf();
    assertTrue(channel.writeInbound(settingsFrame));
    assertEquals(1, userEvents.size());
    assertTrue(userEvents.get(0) instanceof PriorKnowledgeUpgradeEvent);
}
Also used : PriorKnowledgeUpgradeEvent(io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) UpgradeCodecFactory(io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) ByteBuf(io.netty.buffer.ByteBuf) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 PriorKnowledgeUpgradeEvent (io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler.PriorKnowledgeUpgradeEvent)3 Test (org.junit.jupiter.api.Test)3 Channel (io.netty.channel.Channel)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)1 HttpServerUpgradeHandler (io.netty.handler.codec.http.HttpServerUpgradeHandler)1 UpgradeCodecFactory (io.netty.handler.codec.http.HttpServerUpgradeHandler.UpgradeCodecFactory)1