Search in sources :

Example 11 with DefaultHttp2Headers

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

the class InboundHttp2ToHttpAdapterTest method clientRequestOneDataFrame.

@Test
public void clientRequestOneDataFrame() throws Exception {
    boostrapEnv(1, 1, 1);
    final String text = "hello world";
    final ByteBuf content = Unpooled.copiedBuffer(text.getBytes());
    final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/path/resource2", content, true);
    try {
        HttpHeaders httpHeaders = request.headers();
        httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
        httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, text.length());
        httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
        final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/some/path/resource2"));
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, false, newPromiseClient());
                clientHandler.encoder().writeData(ctxClient(), 3, content.retainedDuplicate(), 0, true, newPromiseClient());
                clientChannel.flush();
            }
        });
        awaitRequests();
        ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
        verify(serverListener).messageReceived(requestCaptor.capture());
        capturedRequests = requestCaptor.getAllValues();
        assertEquals(request, capturedRequests.get(0));
    } finally {
        request.release();
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) FullHttpMessage(io.netty.handler.codec.http.FullHttpMessage) AsciiString(io.netty.util.AsciiString) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 12 with DefaultHttp2Headers

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

the class InboundHttp2ToHttpAdapterTest method clientRequestSingleHeaderCookieSplitIntoMultipleEntries.

@Test
public void clientRequestSingleHeaderCookieSplitIntoMultipleEntries() throws Exception {
    boostrapEnv(1, 1, 1);
    final FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/some/path/resource2", true);
    try {
        HttpHeaders httpHeaders = request.headers();
        httpHeaders.set(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), "https");
        httpHeaders.set(HttpHeaderNames.HOST, "example.org");
        httpHeaders.setInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), 3);
        httpHeaders.setInt(HttpHeaderNames.CONTENT_LENGTH, 0);
        httpHeaders.set(HttpHeaderNames.COOKIE, "a=b; c=d; e=f");
        httpHeaders.setShort(HttpConversionUtil.ExtensionHeaderNames.STREAM_WEIGHT.text(), (short) 16);
        final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).scheme(new AsciiString("https")).authority(new AsciiString("example.org")).path(new AsciiString("/some/path/resource2")).add(HttpHeaderNames.COOKIE, "a=b").add(HttpHeaderNames.COOKIE, "c=d").add(HttpHeaderNames.COOKIE, "e=f");
        runInChannel(clientChannel, new Http2Runnable() {

            @Override
            public void run() throws Http2Exception {
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, true, newPromiseClient());
                clientChannel.flush();
            }
        });
        awaitRequests();
        ArgumentCaptor<FullHttpMessage> requestCaptor = ArgumentCaptor.forClass(FullHttpMessage.class);
        verify(serverListener).messageReceived(requestCaptor.capture());
        capturedRequests = requestCaptor.getAllValues();
        assertEquals(request, capturedRequests.get(0));
    } finally {
        request.release();
    }
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) FullHttpMessage(io.netty.handler.codec.http.FullHttpMessage) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 13 with DefaultHttp2Headers

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

the class Http2FrameWriterBenchmark method createHeaders.

private static Http2Headers createHeaders(int numValues, int nameLength, int valueLength) {
    Http2Headers headers = new DefaultHttp2Headers();
    Random r = new Random();
    for (int i = 0; i < numValues; ++i) {
        byte[] tmp = new byte[nameLength];
        r.nextBytes(tmp);
        AsciiString name = new AsciiString(tmp);
        tmp = new byte[valueLength];
        r.nextBytes(tmp);
        headers.add(name, new AsciiString(tmp));
    }
    return headers;
}
Also used : Random(java.util.Random) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString)

Example 14 with DefaultHttp2Headers

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

the class ReadOnlyHttp2HeadersBenchmark method defaultServerHeaders.

@Benchmark
@BenchmarkMode(Mode.AverageTime)
public int defaultServerHeaders() {
    Http2Headers headers = new DefaultHttp2Headers(false);
    for (int i = 0; i < headerCount; ++i) {
        headers.add(headerNames[i], headerValues[i]);
    }
    headers.status(HttpResponseStatus.OK.codeAsText());
    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 15 with DefaultHttp2Headers

use of io.netty.handler.codec.http2.DefaultHttp2Headers 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.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