Search in sources :

Example 1 with GrpcHttp2RequestHeaders

use of io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders 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 2 with GrpcHttp2RequestHeaders

use of io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders 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)

Example 3 with GrpcHttp2RequestHeaders

use of io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders in project grpc-java by grpc.

the class GrpcHttp2InboundHeadersTest method basicCorrectness.

@Test
public void basicCorrectness() {
    Http2Headers headers = new GrpcHttp2RequestHeaders(1);
    headers.add(of(":method"), of("POST"));
    headers.add(of("content-type"), of("application/grpc+proto"));
    headers.add(of(":path"), of("/google.pubsub.v2.PublisherService/CreateTopic"));
    headers.add(of(":scheme"), of("https"));
    headers.add(of("te"), of("trailers"));
    headers.add(of(":authority"), of("pubsub.googleapis.com"));
    headers.add(of("foo"), of("bar"));
    assertEquals(7, headers.size());
    // Number of headers without the pseudo headers and 'te' header.
    assertEquals(2, ((GrpcHttp2InboundHeaders) headers).numHeaders());
    assertEquals(of("application/grpc+proto"), headers.get(of("content-type")));
    assertEquals(of("/google.pubsub.v2.PublisherService/CreateTopic"), headers.path());
    assertEquals(of("https"), headers.scheme());
    assertEquals(of("POST"), headers.method());
    assertEquals(of("pubsub.googleapis.com"), headers.authority());
    assertEquals(of("trailers"), headers.get(of("te")));
    assertEquals(of("bar"), headers.get(of("foo")));
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) GrpcHttp2RequestHeaders(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders) Test(org.junit.Test)

Example 4 with GrpcHttp2RequestHeaders

use of io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders in project grpc-java by grpc.

the class GrpcHttp2InboundHeadersTest method binaryHeadersShouldBeBase64Decoded.

@Test
public void binaryHeadersShouldBeBase64Decoded() {
    Http2Headers headers = new GrpcHttp2RequestHeaders(1);
    byte[] data = new byte[100];
    new Random().nextBytes(data);
    headers.add(of("foo-bin"), of(BASE64_ENCODING_OMIT_PADDING.encode(data)));
    assertEquals(1, headers.size());
    byte[][] namesAndValues = ((GrpcHttp2InboundHeaders) headers).namesAndValues();
    assertEquals(of("foo-bin"), new AsciiString(namesAndValues[0]));
    assertNotSame(data, namesAndValues[1]);
    assertArrayEquals(data, namesAndValues[1]);
}
Also used : Random(java.util.Random) Http2Headers(io.netty.handler.codec.http2.Http2Headers) GrpcHttp2RequestHeaders(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders) GrpcHttp2InboundHeaders(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2InboundHeaders) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 5 with GrpcHttp2RequestHeaders

use of io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders in project grpc-java by grpc.

the class GrpcHttp2HeadersUtilsTest method headerGetAll_multiplePresent.

@Test
public void headerGetAll_multiplePresent() {
    // getAll is used by Netty 4.1.60+. https://github.com/grpc/grpc-java/issues/7953
    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.size()).isEqualTo(5);
    assertThat(http2Headers.getAll(AsciiString.of("multiple"))).containsExactly(AsciiString.of("value1"), AsciiString.of("value2"));
}
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

GrpcHttp2RequestHeaders (io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2RequestHeaders)8 Http2Headers (io.netty.handler.codec.http2.Http2Headers)8 Test (org.junit.Test)8 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)6 Metadata (io.grpc.Metadata)1 GrpcHttp2InboundHeaders (io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2InboundHeaders)1 AsciiString (io.netty.util.AsciiString)1 Random (java.util.Random)1