use of io.netty.util.AsciiString 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(BaseEncoding.base64().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.util.AsciiString in project grpc-java by grpc.
the class NettyServerHandlerTest method headersWithInvalidContentTypeShouldFail.
@Test
public void headersWithInvalidContentTypeShouldFail() throws Exception {
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);
verifyWrite().writeRstStream(eq(ctx()), eq(STREAM_ID), eq(Http2Error.REFUSED_STREAM.code()), any(ChannelPromise.class));
}
use of io.netty.util.AsciiString in project grpc-java by grpc.
the class NettyServerStreamTest method emptyFramerShouldSendNoPayload.
@Test
public void emptyFramerShouldSendNoPayload() {
ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(new AsciiString("200")).set(new AsciiString("content-type"), new AsciiString("application/grpc")).set(new AsciiString("grpc-status"), new AsciiString("0")));
ArgumentCaptor<SendResponseHeadersCommand> cmdCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
stream().close(Status.OK, new Metadata());
verify(writeQueue).enqueue(cmdCap.capture(), eq(true));
SendResponseHeadersCommand cmd = cmdCap.getValue();
assertThat(cmd.stream()).isSameAs(stream.transportState());
assertThat(ImmutableListMultimap.copyOf(cmd.headers())).containsExactlyEntriesIn(expectedHeaders);
assertThat(cmd.endOfStream()).isTrue();
}
use of io.netty.util.AsciiString in project grpc-java by grpc.
the class NettyServerStreamTest method closeAfterClientHalfCloseShouldSucceed.
@Test
public void closeAfterClientHalfCloseShouldSucceed() throws Exception {
ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(new AsciiString("200")).set(new AsciiString("content-type"), new AsciiString("application/grpc")).set(new AsciiString("grpc-status"), new AsciiString("0")));
// Client half-closes. Listener gets halfClosed()
stream().transportState().inboundDataReceived(new EmptyByteBuf(UnpooledByteBufAllocator.DEFAULT), true);
verify(serverListener).halfClosed();
// Server closes. Status sent
stream().close(Status.OK, trailers);
verifyNoMoreInteractions(serverListener);
ArgumentCaptor<SendResponseHeadersCommand> cmdCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
verify(writeQueue).enqueue(cmdCap.capture(), eq(true));
SendResponseHeadersCommand cmd = cmdCap.getValue();
assertThat(cmd.stream()).isSameAs(stream.transportState());
assertThat(ImmutableListMultimap.copyOf(cmd.headers())).containsExactlyEntriesIn(expectedHeaders);
assertThat(cmd.endOfStream()).isTrue();
// Sending and receiving complete. Listener gets closed()
stream().transportState().complete();
verify(serverListener).closed(Status.OK);
verifyNoMoreInteractions(serverListener);
}
use of io.netty.util.AsciiString in project grpc-java by grpc.
the class NettyServerStreamTest method closeBeforeClientHalfCloseShouldSucceed.
@Test
public void closeBeforeClientHalfCloseShouldSucceed() throws Exception {
ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(new AsciiString("200")).set(new AsciiString("content-type"), new AsciiString("application/grpc")).set(new AsciiString("grpc-status"), new AsciiString("0")));
stream().close(Status.OK, new Metadata());
ArgumentCaptor<SendResponseHeadersCommand> sendHeadersCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
verify(writeQueue).enqueue(sendHeadersCap.capture(), eq(true));
SendResponseHeadersCommand sendHeaders = sendHeadersCap.getValue();
assertThat(sendHeaders.stream()).isSameAs(stream.transportState());
assertThat(ImmutableListMultimap.copyOf(sendHeaders.headers())).containsExactlyEntriesIn(expectedHeaders);
assertThat(sendHeaders.endOfStream()).isTrue();
verifyZeroInteractions(serverListener);
// Sending complete. Listener gets closed()
stream().transportState().complete();
verify(serverListener).closed(Status.OK);
verifyZeroInteractions(serverListener);
}
Aggregations