Search in sources :

Example 31 with Http2Exception

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

the class DataCompressionHttp2Test method deflateEncodingWriteLargeMessage.

@Test
public void deflateEncodingWriteLargeMessage() throws Exception {
    final int BUFFER_SIZE = 1 << 12;
    final byte[] bytes = new byte[BUFFER_SIZE];
    new Random().nextBytes(bytes);
    bootstrapEnv(BUFFER_SIZE);
    final ByteBuf data = Unpooled.wrappedBuffer(bytes);
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.DEFLATE);
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient());
                clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient());
                clientHandler.flush(ctxClient());
            }
        });
        awaitServer();
        assertEquals(data.resetReaderIndex().toString(CharsetUtil.UTF_8), serverOut.toString(CharsetUtil.UTF_8.name()));
    } finally {
        data.release();
    }
}
Also used : Random(java.util.Random) Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 32 with Http2Exception

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

the class DataCompressionHttp2Test method brotliEncodingSingleMessage.

@Test
public void brotliEncodingSingleMessage() throws Exception {
    final String text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccc";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes(CharsetUtil.UTF_8.name()));
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.BR);
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientEncoder.writeHeaders(ctxClient(), 3, headers, 0, false, newPromiseClient());
                clientEncoder.writeData(ctxClient(), 3, data.retain(), 0, true, newPromiseClient());
                clientHandler.flush(ctxClient());
            }
        });
        awaitServer();
        assertEquals(text, serverOut.toString(CharsetUtil.UTF_8.name()));
    } finally {
        data.release();
    }
}
Also used : Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 33 with Http2Exception

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

the class Http2FrameCodecTest method flowControlShouldBeResilientToMissingStreams.

@Test
public void flowControlShouldBeResilientToMissingStreams() throws Http2Exception {
    Http2Connection conn = new DefaultHttp2Connection(true);
    Http2ConnectionEncoder enc = new DefaultHttp2ConnectionEncoder(conn, new DefaultHttp2FrameWriter());
    Http2ConnectionDecoder dec = new DefaultHttp2ConnectionDecoder(conn, enc, new DefaultHttp2FrameReader());
    Http2FrameCodec codec = new Http2FrameCodec(enc, dec, new Http2Settings(), false);
    EmbeddedChannel em = new EmbeddedChannel(codec);
    // We call #consumeBytes on a stream id which has not been seen yet to emulate the case
    // where a stream is deregistered which in reality can happen in response to a RST.
    assertFalse(codec.consumeBytes(1, 1));
    assertTrue(em.finishAndReleaseAll());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Http2TestUtil.anyHttp2Settings(io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings) Test(org.junit.jupiter.api.Test)

Example 34 with Http2Exception

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

the class Http2FrameCodecTest method receiveSettings.

@Test
public void receiveSettings() throws Http2Exception {
    Http2Settings settings = new Http2Settings().maxConcurrentStreams(1);
    frameInboundWriter.writeInboundSettings(settings);
    Http2SettingsFrame settingsFrame = inboundHandler.readInbound();
    assertNotNull(settingsFrame);
    assertEquals(settings, settingsFrame.settings());
}
Also used : Http2TestUtil.anyHttp2Settings(io.netty.handler.codec.http2.Http2TestUtil.anyHttp2Settings) Test(org.junit.jupiter.api.Test)

Example 35 with Http2Exception

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

the class Http2FrameCodecTest method streamIdentifiersExhausted.

@Test
public void streamIdentifiersExhausted() throws Http2Exception {
    int maxServerStreamId = Integer.MAX_VALUE - 1;
    assertNotNull(frameCodec.connection().local().createStream(maxServerStreamId, false));
    Http2FrameStream stream = frameCodec.newStream();
    assertNotNull(stream);
    ChannelPromise writePromise = channel.newPromise();
    channel.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()).stream(stream), writePromise);
    Http2GoAwayFrame goAwayFrame = inboundHandler.readInbound();
    assertNotNull(goAwayFrame);
    assertEquals(NO_ERROR.code(), goAwayFrame.errorCode());
    assertEquals(Integer.MAX_VALUE, goAwayFrame.lastStreamId());
    goAwayFrame.release();
    assertThat(writePromise.cause(), instanceOf(Http2NoMoreStreamIdsException.class));
}
Also used : ChannelPromise(io.netty.channel.ChannelPromise) Http2TestUtil.anyChannelPromise(io.netty.handler.codec.http2.Http2TestUtil.anyChannelPromise) Test(org.junit.jupiter.api.Test)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)109 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)100 ChannelFuture (io.netty.channel.ChannelFuture)92 Test (org.junit.Test)89 Http2Exception (io.netty.handler.codec.http2.Http2Exception)85 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 AtomicReference (java.util.concurrent.atomic.AtomicReference)78 ByteArrayOutputStream (java.io.ByteArrayOutputStream)76 Channel (io.netty.channel.Channel)75 ChannelPipeline (io.netty.channel.ChannelPipeline)75 ArrayList (java.util.ArrayList)75 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)75 ChannelInitializer (io.netty.channel.ChannelInitializer)74 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)74 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)74 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)74 Http2Headers (io.netty.handler.codec.http2.Http2Headers)74 ApplicationProtocolNames (io.netty.handler.ssl.ApplicationProtocolNames)74 ApplicationProtocolNegotiationHandler (io.netty.handler.ssl.ApplicationProtocolNegotiationHandler)74 SslHandler (io.netty.handler.ssl.SslHandler)74