use of io.netty.handler.codec.http2.Http2Headers 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")));
}
use of io.netty.handler.codec.http2.Http2Headers 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]);
}
use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.
the class NettyServerHandlerTest method headersWithAuthorityAndHostUsesAuthority.
@Test
public void headersWithAuthorityAndHostUsesAuthority() throws Exception {
manualSetUp();
Http2Headers headers = new DefaultHttp2Headers().method(HTTP_METHOD).authority("example.com").set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).add(AsciiString.of("host"), AsciiString.of("bad.com")).path(new AsciiString("/foo/bar"));
ByteBuf headersFrame = headersFrame(STREAM_ID, headers);
channelRead(headersFrame);
Metadata.Key<String> hostKey = Metadata.Key.of("host", Metadata.ASCII_STRING_MARSHALLER);
ArgumentCaptor<NettyServerStream> streamCaptor = ArgumentCaptor.forClass(NettyServerStream.class);
ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
verify(transportListener).streamCreated(streamCaptor.capture(), eq("foo/bar"), metadataCaptor.capture());
Truth.assertThat(streamCaptor.getValue().getAuthority()).isEqualTo("example.com");
Truth.assertThat(metadataCaptor.getValue().get(hostKey)).isNull();
}
use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.
the class NettyServerHandlerTest method headersWithInvalidContentTypeShouldFail.
@Test
public void headersWithInvalidContentTypeShouldFail() throws Exception {
manualSetUp();
Http2Headers headers = new DefaultHttp2Headers().method(HTTP_METHOD).set(CONTENT_TYPE_HEADER, new AsciiString("application/bad", UTF_8)).set(TE_HEADER, TE_TRAILERS).path(new AsciiString("/foo/bar"));
ByteBuf headersFrame = headersFrame(STREAM_ID, headers);
channelRead(headersFrame);
Http2Headers responseHeaders = new DefaultHttp2Headers().set(InternalStatus.CODE_KEY.name(), String.valueOf(Code.INTERNAL.value())).set(InternalStatus.MESSAGE_KEY.name(), "Content-Type 'application/bad' is not supported").status("" + 415).set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8");
verifyWrite().writeHeaders(eq(ctx()), eq(STREAM_ID), eq(responseHeaders), eq(0), eq(false), any(ChannelPromise.class));
}
use of io.netty.handler.codec.http2.Http2Headers in project grpc-java by grpc.
the class NettyServerHandlerTest method headersWithMissingPathShouldFail.
@Test
public void headersWithMissingPathShouldFail() throws Exception {
manualSetUp();
Http2Headers headers = new DefaultHttp2Headers().method(HTTP_METHOD).set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC);
ByteBuf headersFrame = headersFrame(STREAM_ID, headers);
channelRead(headersFrame);
Http2Headers responseHeaders = new DefaultHttp2Headers().set(InternalStatus.CODE_KEY.name(), String.valueOf(Code.UNIMPLEMENTED.value())).set(InternalStatus.MESSAGE_KEY.name(), "Expected path but is missing").status("" + 404).set(CONTENT_TYPE_HEADER, "text/plain; charset=utf-8");
verifyWrite().writeHeaders(eq(ctx()), eq(STREAM_ID), eq(responseHeaders), eq(0), eq(false), any(ChannelPromise.class));
}
Aggregations