Search in sources :

Example 56 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class InboundHttp2ToHttpAdapterTest method clientRequestSingleHeaderCookieSplitIntoMultipleEntries2.

@Test
public void clientRequestSingleHeaderCookieSplitIntoMultipleEntries2() 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; 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 57 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class InboundHttp2ToHttpAdapterTest method clientRequestTrailingHeaders.

@Test
public void clientRequestTrailingHeaders() throws Exception {
    boostrapEnv(1, 1, 1);
    final String text = "some data";
    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);
        HttpHeaders trailingHeaders = request.trailingHeaders();
        trailingHeaders.set(of("Foo"), of("goo"));
        trailingHeaders.set(of("fOo2"), of("goo2"));
        trailingHeaders.add(of("foO2"), of("goo3"));
        final Http2Headers http2Headers = new DefaultHttp2Headers().method(new AsciiString("GET")).path(new AsciiString("/some/path/resource2"));
        final Http2Headers http2Headers2 = new DefaultHttp2Headers().set(new AsciiString("foo"), new AsciiString("goo")).set(new AsciiString("foo2"), new AsciiString("goo2")).add(new AsciiString("foo2"), new AsciiString("goo3"));
        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, false, newPromiseClient());
                clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers2, 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 58 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class InboundHttp2ToHttpAdapterTest method clientRequestSingleHeaderNonAsciiShouldThrow.

@Test
public void clientRequestSingleHeaderNonAsciiShouldThrow() throws Exception {
    boostrapEnv(1, 1, 1);
    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(new AsciiString("çã".getBytes(CharsetUtil.UTF_8)), new AsciiString("Ãã".getBytes(CharsetUtil.UTF_8)));
    runInChannel(clientChannel, new Http2Runnable() {

        @Override
        public void run() throws Http2Exception {
            clientHandler.encoder().writeHeaders(ctxClient(), 3, http2Headers, 0, true, newPromiseClient());
            clientChannel.flush();
        }
    });
    awaitResponses();
    assertTrue(isStreamError(clientException));
}
Also used : Http2CodecUtil.getEmbeddedHttp2Exception(io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception) Http2Runnable(io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 59 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class HpackHuffmanTest method decode.

private static byte[] decode(HpackHuffmanDecoder decoder, byte[] bytes) throws Http2Exception {
    ByteBuf buffer = Unpooled.wrappedBuffer(bytes);
    try {
        AsciiString decoded = decoder.decode(buffer, buffer.readableBytes());
        Assert.assertFalse(buffer.isReadable());
        return decoded.toByteArray();
    } finally {
        buffer.release();
    }
}
Also used : AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf)

Example 60 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class HpackHuffmanTest method roundTrip.

private static void roundTrip(HpackHuffmanEncoder encoder, HpackHuffmanDecoder decoder, byte[] buf) throws Http2Exception {
    ByteBuf buffer = Unpooled.buffer();
    try {
        encoder.encode(buffer, new AsciiString(buf, false));
        byte[] bytes = new byte[buffer.readableBytes()];
        buffer.readBytes(bytes);
        byte[] actualBytes = decode(decoder, bytes);
        Assert.assertTrue(Arrays.equals(buf, actualBytes));
    } finally {
        buffer.release();
    }
}
Also used : AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

AsciiString (io.netty.util.AsciiString)73 Test (org.junit.Test)43 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)27 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)26 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)25 ByteBuf (io.netty.buffer.ByteBuf)18 ChannelPromise (io.netty.channel.ChannelPromise)15 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)12 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)12 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)12 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 Http2Headers (io.netty.handler.codec.http2.Http2Headers)9 Metadata (io.grpc.Metadata)8 ChannelFuture (io.netty.channel.ChannelFuture)4 Status (io.grpc.Status)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Setup (org.openjdk.jmh.annotations.Setup)3 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)2