Search in sources :

Example 11 with Http2HeadersFrame

use of io.netty.handler.codec.http2.Http2HeadersFrame in project netty by netty.

the class Http2FrameCodecTest method streamErrorShouldFireExceptionForInbound.

@Test
public void streamErrorShouldFireExceptionForInbound() throws Exception {
    frameInboundWriter.writeInboundHeaders(3, request, 31, false);
    Http2Stream stream = frameCodec.connection().stream(3);
    assertNotNull(stream);
    StreamException streamEx = new StreamException(3, Http2Error.INTERNAL_ERROR, "foo");
    channel.pipeline().fireExceptionCaught(streamEx);
    Http2FrameStreamEvent event = inboundHandler.readInboundMessageOrUserEvent();
    assertEquals(Http2FrameStreamEvent.Type.State, event.type());
    assertEquals(State.OPEN, event.stream().state());
    Http2HeadersFrame headersFrame = inboundHandler.readInboundMessageOrUserEvent();
    assertNotNull(headersFrame);
    Http2FrameStreamException e = assertThrows(Http2FrameStreamException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            inboundHandler.checkException();
        }
    });
    assertEquals(streamEx, e.getCause());
    assertNull(inboundHandler.readInboundMessageOrUserEvent());
}
Also used : Executable(org.junit.jupiter.api.function.Executable) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) Test(org.junit.jupiter.api.Test)

Example 12 with Http2HeadersFrame

use of io.netty.handler.codec.http2.Http2HeadersFrame in project netty by netty.

the class Http2MultiplexTest method useReadWithoutAutoReadBuffered.

private void useReadWithoutAutoReadBuffered(final boolean triggerOnReadComplete) {
    LastInboundHandler inboundHandler = new LastInboundHandler();
    Http2StreamChannel childChannel = newInboundStream(3, false, inboundHandler);
    assertTrue(childChannel.config().isAutoRead());
    childChannel.config().setAutoRead(false);
    assertFalse(childChannel.config().isAutoRead());
    Http2HeadersFrame headersFrame = inboundHandler.readInbound();
    assertNotNull(headersFrame);
    // Write some bytes to get the channel into the idle state with buffered data and also verify we
    // do not dispatch it until we receive a read() call.
    frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("hello world"), 0, false);
    frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("foo"), 0, false);
    frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("bar"), 0, false);
    // Add a handler which will request reads.
    childChannel.pipeline().addFirst(new ChannelInboundHandlerAdapter() {

        @Override
        public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
            super.channelReadComplete(ctx);
            if (triggerOnReadComplete) {
                ctx.read();
                ctx.read();
            }
        }

        @Override
        public void channelRead(ChannelHandlerContext ctx, Object msg) {
            ctx.fireChannelRead(msg);
            if (!triggerOnReadComplete) {
                ctx.read();
                ctx.read();
            }
        }
    });
    inboundHandler.channel().read();
    verifyFramesMultiplexedToCorrectChannel(childChannel, inboundHandler, 3);
    frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("hello world2"), 0, false);
    frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("foo2"), 0, false);
    frameInboundWriter.writeInboundData(childChannel.stream().id(), bb("bar2"), 0, true);
    verifyFramesMultiplexedToCorrectChannel(childChannel, inboundHandler, 3);
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Example 13 with Http2HeadersFrame

use of io.netty.handler.codec.http2.Http2HeadersFrame in project reactor-netty by reactor.

the class AccessLogHandlerH2 method channelRead.

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof Http2HeadersFrame) {
        final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg;
        if (accessLogArgProvider == null) {
            accessLogArgProvider = new AccessLogArgProviderH2(ctx.channel().remoteAddress());
        }
        accessLogArgProvider.requestHeaders(requestHeaders);
    }
    ctx.fireChannelRead(msg);
}
Also used : Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame)

Aggregations

StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)6 Http2HeadersFrame (io.netty.handler.codec.http2.Http2HeadersFrame)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)3 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)3 DefaultHttp2HeadersFrame (io.netty.handler.codec.http2.DefaultHttp2HeadersFrame)3 Http2DataFrame (io.netty.handler.codec.http2.Http2DataFrame)3 Test (org.junit.jupiter.api.Test)3 Channel (io.netty.channel.Channel)2 Http2Headers (io.netty.handler.codec.http2.Http2Headers)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 Test (org.junit.Test)2 RequestInfo (com.github.ambry.network.RequestInfo)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelProgressiveFuture (io.netty.channel.ChannelProgressiveFuture)1 ChannelProgressiveFutureListener (io.netty.channel.ChannelProgressiveFutureListener)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1