List of usage examples for io.netty.util AsciiString of
public static AsciiString of(CharSequence string)
From source file:io.grpc.netty.GrpcHpackStaticTable.java
License:Apache License
private static GrpcHpackHeaderField newHeaderField(CharSequence name, CharSequence value) { return new GrpcHpackHeaderField(AsciiString.of(name), AsciiString.of(value)); }
From source file:io.grpc.netty.GrpcHttp2HeadersUtilsTest.java
License:Apache License
@Test public void dupBinHeadersWithComma() { Key<byte[]> key = Key.of("bytes-bin", BINARY_BYTE_MARSHALLER); Http2Headers http2Headers = new GrpcHttp2RequestHeaders(2); http2Headers.add(AsciiString.of("bytes-bin"), AsciiString.of("BaS,e6,,4+,padding==")); http2Headers.add(AsciiString.of("bytes-bin"), AsciiString.of("more")); http2Headers.add(AsciiString.of("bytes-bin"), AsciiString.of("")); Metadata recoveredHeaders = Utils.convertHeaders(http2Headers); byte[][] values = Iterables.toArray(recoveredHeaders.getAll(key), byte[].class); assertTrue(Arrays.deepEquals(new byte[][] { BaseEncoding.base64().decode("BaS"), BaseEncoding.base64().decode("e6"), BaseEncoding.base64().decode(""), BaseEncoding.base64().decode("4+"), BaseEncoding.base64().decode("padding"), BaseEncoding.base64().decode("more"), BaseEncoding.base64().decode("") }, values)); }
From source file:io.grpc.netty.InboundHeadersBenchmark.java
License:Apache License
private static void setupRequestHeaders() { requestHeaders = new AsciiString[18]; int i = 0;/* w ww . j a va 2 s . co m*/ requestHeaders[i++] = AsciiString.of(":method"); requestHeaders[i++] = AsciiString.of("POST"); requestHeaders[i++] = AsciiString.of(":scheme"); requestHeaders[i++] = AsciiString.of("http"); requestHeaders[i++] = AsciiString.of(":path"); requestHeaders[i++] = AsciiString.of("/google.pubsub.v2.PublisherService/CreateTopic"); requestHeaders[i++] = AsciiString.of(":authority"); requestHeaders[i++] = AsciiString.of("pubsub.googleapis.com"); requestHeaders[i++] = AsciiString.of("te"); requestHeaders[i++] = AsciiString.of("trailers"); requestHeaders[i++] = AsciiString.of("grpc-timeout"); requestHeaders[i++] = AsciiString.of("1S"); requestHeaders[i++] = AsciiString.of("content-type"); requestHeaders[i++] = AsciiString.of("application/grpc+proto"); requestHeaders[i++] = AsciiString.of("grpc-encoding"); requestHeaders[i++] = AsciiString.of("gzip"); requestHeaders[i++] = AsciiString.of("authorization"); requestHeaders[i] = AsciiString.of("Bearer y235.wef315yfh138vh31hv93hv8h3v"); }
From source file:io.grpc.netty.InboundHeadersBenchmark.java
License:Apache License
private static void setupResponseHeaders() { responseHeaders = new AsciiString[4]; int i = 0;//from w ww .j a v a2 s . c o m responseHeaders[i++] = AsciiString.of(":status"); responseHeaders[i++] = AsciiString.of("200"); responseHeaders[i++] = AsciiString.of("grpc-encoding"); responseHeaders[i] = AsciiString.of("gzip"); }
From source file:io.grpc.netty.NettyClientStream.java
License:Apache License
@Override public void setAuthority(String authority) { this.authority = AsciiString.of(checkNotNull(authority, "authority")); }
From source file:io.grpc.netty.NettyClientStreamTest.java
License:Apache License
@Test public void setHttp2StreamShouldNotifyReady() { listener = mock(ClientStreamListener.class); stream = new NettyClientStream(new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE), methodDescriptor, new Metadata(), channel, AsciiString.of("localhost"), AsciiString.of("http"), AsciiString.of("agent"), StatsTraceContext.NOOP, transportTracer, CallOptions.DEFAULT); stream.start(listener);/*from w w w . j av a 2s . c o m*/ stream().transportState().setId(STREAM_ID); verify(listener, never()).onReady(); assertFalse(stream.isReady()); stream().transportState().setHttp2Stream(http2Stream); verify(listener).onReady(); assertTrue(stream.isReady()); }
From source file:io.grpc.netty.NettyClientStreamTest.java
License:Apache License
@Test public void removeUserAgentFromApplicationHeaders() { Metadata metadata = new Metadata(); metadata.put(GrpcUtil.USER_AGENT_KEY, "bad agent"); listener = mock(ClientStreamListener.class); Mockito.reset(writeQueue);/*from w w w. ja v a 2 s .c o m*/ ChannelPromise completedPromise = new DefaultChannelPromise(channel).setSuccess(); when(writeQueue.enqueue(any(QueuedCommand.class), anyBoolean())).thenReturn(completedPromise); stream = new NettyClientStream(new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE), methodDescriptor, new Metadata(), channel, AsciiString.of("localhost"), AsciiString.of("http"), AsciiString.of("good agent"), StatsTraceContext.NOOP, transportTracer, CallOptions.DEFAULT); stream.start(listener); ArgumentCaptor<CreateStreamCommand> cmdCap = ArgumentCaptor.forClass(CreateStreamCommand.class); verify(writeQueue).enqueue(cmdCap.capture(), eq(false)); assertThat(ImmutableListMultimap.copyOf(cmdCap.getValue().headers())).containsEntry(Utils.USER_AGENT, AsciiString.of("good agent")); }
From source file:io.grpc.netty.NettyClientStreamTest.java
License:Apache License
@Test public void getRequestSentThroughHeader() { // Creating a GET method MethodDescriptor<?, ?> descriptor = MethodDescriptor.<Void, Void>newBuilder() .setType(MethodDescriptor.MethodType.UNARY).setFullMethodName("testService/test") .setRequestMarshaller(marshaller).setResponseMarshaller(marshaller).setIdempotent(true) .setSafe(true).build();/*from ww w. j a va 2 s .c om*/ NettyClientStream stream = new NettyClientStream(new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE), descriptor, new Metadata(), channel, AsciiString.of("localhost"), AsciiString.of("http"), AsciiString.of("agent"), StatsTraceContext.NOOP, transportTracer, CallOptions.DEFAULT); stream.start(listener); stream.transportState().setId(STREAM_ID); stream.transportState().setHttp2Stream(http2Stream); byte[] msg = smallMessage(); stream.writeMessage(new ByteArrayInputStream(msg)); stream.flush(); stream.halfClose(); ArgumentCaptor<CreateStreamCommand> cmdCap = ArgumentCaptor.forClass(CreateStreamCommand.class); verify(writeQueue).enqueue(cmdCap.capture(), eq(true)); ImmutableListMultimap<CharSequence, CharSequence> headers = ImmutableListMultimap .copyOf(cmdCap.getValue().headers()); assertThat(headers).containsEntry(AsciiString.of(":method"), Utils.HTTP_GET_METHOD); assertThat(headers).containsEntry(AsciiString.of(":path"), AsciiString.of("/testService/test?" + BaseEncoding.base64().encode(msg))); }
From source file:io.grpc.netty.NettyClientStreamTest.java
License:Apache License
@Override protected NettyClientStream createStream() { when(handler.getWriteQueue()).thenReturn(writeQueue); NettyClientStream stream = new NettyClientStream(new TransportStateImpl(handler, DEFAULT_MAX_MESSAGE_SIZE), methodDescriptor, new Metadata(), channel, AsciiString.of("localhost"), AsciiString.of("http"), AsciiString.of("agent"), StatsTraceContext.NOOP, transportTracer, CallOptions.DEFAULT); stream.start(listener);//www.j ava2s .c o m stream.transportState().setHttp2Stream(http2Stream); reset(listener); return stream; }
From source file:org.fomky.ratpack.core.session.HeaderBasedSessionId.java
License:Apache License
private Optional<AsciiString> getCookieSessionId() { if (cookieSessionId == null) { if (terminated) { return Optional.empty(); } else {//from w ww .j a v a 2s .co m String match = request.getHeaders().get(cookieConfig.getIdName()); cookieSessionId = match == null ? Optional.empty() : Optional.of(AsciiString.of(match)); } } return cookieSessionId; }