use of io.netty.util.AsciiString in project grpc-java by grpc.
the class NettyServerHandlerTest method createStream.
private void createStream() throws Exception {
Http2Headers headers = new DefaultHttp2Headers().method(HTTP_METHOD).set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).set(TE_HEADER, TE_TRAILERS).path(new AsciiString("/foo/bar"));
ByteBuf headersFrame = headersFrame(STREAM_ID, headers);
channelRead(headersFrame);
ArgumentCaptor<NettyServerStream> streamCaptor = ArgumentCaptor.forClass(NettyServerStream.class);
ArgumentCaptor<String> methodCaptor = ArgumentCaptor.forClass(String.class);
verify(transportListener).streamCreated(streamCaptor.capture(), methodCaptor.capture(), any(Metadata.class));
stream = streamCaptor.getValue();
}
use of io.netty.util.AsciiString in project grpc-java by grpc.
the class NettyClientStreamTest method invalidInboundHeadersCancelStream.
@Test
public void invalidInboundHeadersCancelStream() throws Exception {
stream().transportState().setId(STREAM_ID);
Http2Headers headers = grpcResponseHeaders();
headers.set("random", "4");
headers.remove(CONTENT_TYPE_HEADER);
// Remove once b/16290036 is fixed.
headers.status(new AsciiString("500"));
stream().transportState().transportHeadersReceived(headers, false);
verify(listener, never()).closed(any(Status.class), any(Metadata.class));
// We are now waiting for 100 bytes of error context on the stream, cancel has not yet been
// sent
verify(channel, never()).writeAndFlush(any(CancelClientStreamCommand.class));
stream().transportState().transportDataReceived(Unpooled.buffer(100).writeZero(100), false);
verify(channel, never()).writeAndFlush(any(CancelClientStreamCommand.class));
stream().transportState().transportDataReceived(Unpooled.buffer(1000).writeZero(1000), false);
// Now verify that cancel is sent and an error is reported to the listener
verify(writeQueue).enqueue(any(CancelClientStreamCommand.class), eq(true));
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
verify(listener).closed(captor.capture(), metadataCaptor.capture());
assertEquals(Status.UNKNOWN.getCode(), captor.getValue().getCode());
assertEquals("4", metadataCaptor.getValue().get(Metadata.Key.of("random", Metadata.ASCII_STRING_MARSHALLER)));
}
use of io.netty.util.AsciiString in project netty by netty.
the class DefaultHttpHeadersTest method testAsciiStringKeyRetrievedAsString.
@Test
public void testAsciiStringKeyRetrievedAsString() {
final HttpHeaders headers = new DefaultHttpHeaders(false);
// Test adding AsciiString key and retrieving it using a String key
final String cacheControl = "no-cache";
headers.add(HttpHeaderNames.CACHE_CONTROL, cacheControl);
final String value = headers.getAsString(HttpHeaderNames.CACHE_CONTROL);
assertNotNull(value);
assertEquals(cacheControl, value);
final String value2 = headers.getAsString(HttpHeaderNames.CACHE_CONTROL.toString());
assertNotNull(value2);
assertEquals(cacheControl, value2);
}
use of io.netty.util.AsciiString in project netty by netty.
the class DefaultHttpHeadersTest method testStringKeyRetrievedAsAsciiString.
@Test
public void testStringKeyRetrievedAsAsciiString() {
final HttpHeaders headers = new DefaultHttpHeaders(false);
// Test adding String key and retrieving it using a AsciiString key
final String connection = "keep-alive";
headers.add(of("Connection"), connection);
// Passes
final String value = headers.getAsString(HttpHeaderNames.CONNECTION.toString());
assertNotNull(value);
assertEquals(connection, value);
// Passes
final String value2 = headers.getAsString(HttpHeaderNames.CONNECTION);
assertNotNull(value2);
assertEquals(connection, value2);
}
use of io.netty.util.AsciiString in project netty by netty.
the class StompHeadersTest method testHeadersCaseSensitive.
@Test
public void testHeadersCaseSensitive() {
DefaultStompHeaders headers = new DefaultStompHeaders();
AsciiString foo = new AsciiString("foo");
AsciiString value = new AsciiString("value");
headers.add(foo, value);
assertNull(headers.get("Foo"));
assertEquals(value, headers.get(foo));
assertEquals(value, headers.get(foo.toString()));
}
Aggregations