Search in sources :

Example 56 with Http2Headers

use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method decode_requestHeaders.

@Test
public void decode_requestHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ServerHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    Http2Headers headers = new DefaultHttp2Headers(false);
    headers.add(of(":scheme"), of("https")).add(of(":method"), of("GET")).add(of(":path"), of("index.html")).add(of(":authority"), of("foo.grpc.io")).add(of("custom"), of("header"));
    encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    headers, encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(headers.get(of(":scheme")), decodedHeaders.scheme());
    assertEquals(headers.get(of(":method")), decodedHeaders.method());
    assertEquals(headers.get(of(":path")), decodedHeaders.path());
    assertEquals(headers.get(of(":authority")), decodedHeaders.authority());
    assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
    assertEquals(headers.size(), decodedHeaders.size());
    String toString = decodedHeaders.toString();
    assertContainsKeyAndValue(toString, ":scheme", decodedHeaders.scheme());
    assertContainsKeyAndValue(toString, ":method", decodedHeaders.method());
    assertContainsKeyAndValue(toString, ":path", decodedHeaders.path());
    assertContainsKeyAndValue(toString, ":authority", decodedHeaders.authority());
    assertContainsKeyAndValue(toString, "custom", decodedHeaders.get(of("custom")));
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Test(org.junit.Test)

Example 57 with Http2Headers

use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method headerRemove_multiplePresent.

@Test
public void headerRemove_multiplePresent() {
    Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2);
    http2Headers.add(AsciiString.of("notit1"), AsciiString.of("val1"));
    http2Headers.add(AsciiString.of("multiple"), AsciiString.of("value1"));
    http2Headers.add(AsciiString.of("notit2"), AsciiString.of("val2"));
    http2Headers.add(AsciiString.of("multiple"), AsciiString.of("value2"));
    http2Headers.add(AsciiString.of("notit3"), AsciiString.of("val3"));
    assertThat(http2Headers.remove(AsciiString.of("multiple"))).isTrue();
    assertThat(http2Headers.size()).isEqualTo(3);
    assertThat(http2Headers.getAll(AsciiString.of("notit1"))).containsExactly(AsciiString.of("val1"));
    assertThat(http2Headers.getAll(AsciiString.of("notit2"))).containsExactly(AsciiString.of("val2"));
    assertThat(http2Headers.getAll(AsciiString.of("notit3"))).containsExactly(AsciiString.of("val3"));
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2RequestHeaders(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders) Test(org.junit.Test)

Example 58 with Http2Headers

use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method decode_emptyHeaders.

@Test
public void decode_emptyHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    ByteBuf encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    new DefaultHttp2Headers(false), encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(0, decodedHeaders.size());
    assertThat(decodedHeaders.toString()).contains("[]");
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 59 with Http2Headers

use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method decode_responseHeaders.

@Test
public void decode_responseHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    Http2Headers headers = new DefaultHttp2Headers(false);
    headers.add(of(":status"), of("200")).add(of("custom"), of("header"));
    encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    headers, encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(headers.get(of(":status")), decodedHeaders.get(of(":status")));
    assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
    assertEquals(headers.size(), decodedHeaders.size());
    String toString = decodedHeaders.toString();
    assertContainsKeyAndValue(toString, ":status", decodedHeaders.get(of(":status")));
    assertContainsKeyAndValue(toString, "custom", decodedHeaders.get(of("custom")));
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) AsciiString(io.netty.util.AsciiString) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Test(org.junit.Test)

Example 60 with Http2Headers

use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method headerGetAll_notPresent.

@Test
public void headerGetAll_notPresent() {
    Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2);
    http2Headers.add(AsciiString.of("notit"), AsciiString.of("val"));
    assertThat(http2Headers.getAll(AsciiString.of("dont-care"))).isEmpty();
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2RequestHeaders(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders) Test(org.junit.Test)

Aggregations

Http2Headers (io.netty.handler.codec.http2.Http2Headers)126 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)111 ByteBuf (io.netty.buffer.ByteBuf)103 Test (org.junit.Test)97 ChannelFuture (io.netty.channel.ChannelFuture)76 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)76 AsciiString (io.netty.util.AsciiString)58 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)58 AtomicReference (java.util.concurrent.atomic.AtomicReference)56 ByteArrayOutputStream (java.io.ByteArrayOutputStream)54 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)54 Channel (io.netty.channel.Channel)53 Collections (java.util.Collections)53 ChannelInitializer (io.netty.channel.ChannelInitializer)52 ChannelPipeline (io.netty.channel.ChannelPipeline)52 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)52 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)52 ApplicationProtocolNames (io.netty.handler.ssl.ApplicationProtocolNames)52 ApplicationProtocolNegotiationHandler (io.netty.handler.ssl.ApplicationProtocolNegotiationHandler)52 SslHandler (io.netty.handler.ssl.SslHandler)52