Search in sources :

Example 36 with DefaultHttp2Headers

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

the class HeadersBenchmark method setup.

@Setup(Level.Trial)
public void setup() {
    Map<String, String> headers = ExampleHeaders.EXAMPLES.get(exampleHeader);
    httpNames = new AsciiString[headers.size()];
    http2Names = new AsciiString[headers.size()];
    httpValues = new AsciiString[headers.size()];
    httpHeaders = new DefaultHttpHeaders(false);
    http2Headers = new DefaultHttp2Headers(false);
    int idx = 0;
    for (Map.Entry<String, String> header : headers.entrySet()) {
        String name = header.getKey();
        String httpName = toHttpName(name);
        String http2Name = toHttp2Name(name);
        String value = header.getValue();
        httpNames[idx] = new AsciiString(httpName);
        http2Names[idx] = new AsciiString(http2Name);
        httpValues[idx] = new AsciiString(value);
        httpHeaders.add(httpNames[idx], httpValues[idx]);
        http2Headers.add(http2Names[idx], httpValues[idx]);
        idx++;
    }
    slowHttp2Headers = new SlowHeaders(http2Headers);
    emptyHttpHeaders = new DefaultHttpHeaders(true);
    emptyHttp2Headers = new DefaultHttp2Headers(true);
    emptyHttpHeadersNoValidate = new DefaultHttpHeaders(false);
    emptyHttp2HeadersNoValidate = new DefaultHttp2Headers(false);
}
Also used : DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) AsciiString(io.netty.util.AsciiString) Map(java.util.Map) Setup(org.openjdk.jmh.annotations.Setup)

Example 37 with DefaultHttp2Headers

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

the class ReadOnlyHttp2HeadersBenchmark method defaultClientHeaders.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int defaultClientHeaders() {
    Http2Headers headers = new DefaultHttp2Headers(false);
    for (int i = 0; i < headerCount; ++i) {
        headers.add(headerNames[i], headerValues[i]);
    }
    headers.method(HttpMethod.POST.asciiName());
    headers.scheme(HttpScheme.HTTPS.name());
    headers.path(path);
    headers.authority(authority);
    return iterate(headers);
}
Also used : ReadOnlyHttp2Headers(io.netty.handler.codec.http2.ReadOnlyHttp2Headers) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 38 with DefaultHttp2Headers

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

the class DataCompressionHttp2Test method gzipEncodingSingleEmptyMessage.

@Test
public void gzipEncodingSingleEmptyMessage() throws Exception {
    final String text = "";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes());
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP);
        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.Test)

Example 39 with DefaultHttp2Headers

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

the class DataCompressionHttp2Test method gzipEncodingMultipleMessages.

@Test
public void gzipEncodingMultipleMessages() throws Exception {
    final String text1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccc";
    final String text2 = "dddddddddddddddddddeeeeeeeeeeeeeeeeeeeffffffffffffffffffff";
    final ByteBuf data1 = Unpooled.copiedBuffer(text1.getBytes());
    final ByteBuf data2 = Unpooled.copiedBuffer(text2.getBytes());
    bootstrapEnv(data1.readableBytes() + data2.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP);
        runInChannel(clientChannel, new Http2Runnable() {

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

Example 40 with DefaultHttp2Headers

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

the class DataCompressionHttp2Test method gzipEncodingSingleMessage.

@Test
public void gzipEncodingSingleMessage() throws Exception {
    final String text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccc";
    final ByteBuf data = Unpooled.copiedBuffer(text.getBytes());
    bootstrapEnv(data.readableBytes());
    try {
        final Http2Headers headers = new DefaultHttp2Headers().method(POST).path(PATH).set(HttpHeaderNames.CONTENT_ENCODING, HttpHeaderValues.GZIP);
        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.Test)

Aggregations

Test (org.junit.Test)36 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)32 AsciiString (io.netty.util.AsciiString)32 ByteBuf (io.netty.buffer.ByteBuf)23 Http2Headers (io.netty.handler.codec.http2.Http2Headers)23 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)17 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)12 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)11 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 Metadata (io.grpc.Metadata)7 ChannelFuture (io.netty.channel.ChannelFuture)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)5 Channel (io.netty.channel.Channel)5 Http2Settings (io.netty.handler.codec.http2.Http2Settings)5 ChannelInitializer (io.netty.channel.ChannelInitializer)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 EventLoopGroup (io.netty.channel.EventLoopGroup)4