Search in sources :

Example 1 with GrpcHttp2ClientHeadersDecoder

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

the class NettyClientHandler method newHandler.

static NettyClientHandler newHandler(ClientTransportLifecycleManager lifecycleManager, @Nullable KeepAliveManager keepAliveManager, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, Supplier<Stopwatch> stopwatchFactory, Runnable tooManyPingsRunnable, TransportTracer transportTracer, Attributes eagAttributes, String authority, ChannelLogger negotiationLogger) {
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
    Http2HeadersDecoder headersDecoder = new GrpcHttp2ClientHeadersDecoder(maxHeaderListSize);
    Http2FrameReader frameReader = new DefaultHttp2FrameReader(headersDecoder);
    Http2FrameWriter frameWriter = new DefaultHttp2FrameWriter();
    Http2Connection connection = new DefaultHttp2Connection(false);
    WeightedFairQueueByteDistributor dist = new WeightedFairQueueByteDistributor(connection);
    // Make benchmarks fast again.
    dist.allocationQuantum(16 * 1024);
    DefaultHttp2RemoteFlowController controller = new DefaultHttp2RemoteFlowController(connection, dist);
    connection.remote().flowController(controller);
    return newHandler(connection, frameReader, frameWriter, lifecycleManager, keepAliveManager, autoFlowControl, flowControlWindow, maxHeaderListSize, stopwatchFactory, tooManyPingsRunnable, transportTracer, eagAttributes, authority, negotiationLogger);
}
Also used : DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) DecoratingHttp2FrameWriter(io.netty.handler.codec.http2.DecoratingHttp2FrameWriter) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) Http2FrameWriter(io.netty.handler.codec.http2.Http2FrameWriter) Http2FrameReader(io.netty.handler.codec.http2.Http2FrameReader) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader) DefaultHttp2Connection(io.netty.handler.codec.http2.DefaultHttp2Connection) Http2Connection(io.netty.handler.codec.http2.Http2Connection) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) DefaultHttp2RemoteFlowController(io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) WeightedFairQueueByteDistributor(io.netty.handler.codec.http2.WeightedFairQueueByteDistributor) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader)

Example 2 with GrpcHttp2ClientHeadersDecoder

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

the class GrpcHttp2HeadersUtilsTest method decode_emptyHeaders.

@Test
public void decode_emptyHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    ByteBuf encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    new DefaultHttp2Headers(false), encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(0, decodedHeaders.size());
    assertThat(decodedHeaders.toString()).contains("[]");
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 3 with GrpcHttp2ClientHeadersDecoder

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

the class GrpcHttp2HeadersUtilsTest method decode_responseHeaders.

@Test
public void decode_responseHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    Http2Headers headers = new DefaultHttp2Headers(false);
    headers.add(of(":status"), of("200")).add(of("custom"), of("header"));
    encodedHeaders = Unpooled.buffer();
    encoder.encodeHeaders(1, /* randomly chosen */
    headers, encodedHeaders);
    Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
    encodedHeaders);
    assertEquals(headers.get(of(":status")), decodedHeaders.get(of(":status")));
    assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
    assertEquals(headers.size(), decodedHeaders.size());
    String toString = decodedHeaders.toString();
    assertContainsKeyAndValue(toString, ":status", decodedHeaders.get(of(":status")));
    assertContainsKeyAndValue(toString, "custom", decodedHeaders.get(of("custom")));
}
Also used : DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Http2HeadersEncoder(io.netty.handler.codec.http2.Http2HeadersEncoder) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) AsciiString(io.netty.util.AsciiString) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Test(org.junit.Test)

Example 4 with GrpcHttp2ClientHeadersDecoder

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

the class NettyClientHandlerTest method setUp.

/**
 * Set up for test.
 */
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            StreamListener.MessageProducer producer = (StreamListener.MessageProducer) invocation.getArguments()[0];
            InputStream message;
            while ((message = producer.next()) != null) {
                streamListenerMessageQueue.add(message);
            }
            return null;
        }
    }).when(streamListener).messagesAvailable(ArgumentMatchers.<StreamListener.MessageProducer>any());
    lifecycleManager = new ClientTransportLifecycleManager(listener);
    // it'll be null which will be testing if we behave correctly when it's not present.
    if (setKeepaliveManagerFor.contains(testNameRule.getMethodName())) {
        mockKeepAliveManager = mock(KeepAliveManager.class);
    }
    initChannel(new GrpcHttp2ClientHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
    streamTransportState = new TransportStateImpl(handler(), channel().eventLoop(), DEFAULT_MAX_MESSAGE_SIZE, transportTracer);
    streamTransportState.setListener(streamListener);
    grpcHeaders = new DefaultHttp2Headers().scheme(HTTPS).authority(as("www.fake.com")).path(as("/fakemethod")).method(HTTP_METHOD).add(as("auth"), as("sometoken")).add(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).add(TE_HEADER, TE_TRAILERS);
    // Simulate receipt of initial remote settings.
    ByteBuf serializedSettings = serializeSettings(new Http2Settings());
    channelRead(serializedSettings);
}
Also used : InputStream(java.io.InputStream) ByteBuf(io.netty.buffer.ByteBuf) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) KeepAliveManager(io.grpc.internal.KeepAliveManager) StreamListener(io.grpc.internal.StreamListener) ClientStreamListener(io.grpc.internal.ClientStreamListener) Before(org.junit.Before)

Aggregations

GrpcHttp2ClientHeadersDecoder (io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder)4 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)3 Http2HeadersDecoder (io.netty.handler.codec.http2.Http2HeadersDecoder)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultHttp2HeadersEncoder (io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder)2 Http2Headers (io.netty.handler.codec.http2.Http2Headers)2 Http2HeadersEncoder (io.netty.handler.codec.http2.Http2HeadersEncoder)2 Test (org.junit.Test)2 ClientStreamListener (io.grpc.internal.ClientStreamListener)1 KeepAliveManager (io.grpc.internal.KeepAliveManager)1 StreamListener (io.grpc.internal.StreamListener)1 DecoratingHttp2FrameWriter (io.netty.handler.codec.http2.DecoratingHttp2FrameWriter)1 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)1 DefaultHttp2FrameReader (io.netty.handler.codec.http2.DefaultHttp2FrameReader)1 DefaultHttp2FrameWriter (io.netty.handler.codec.http2.DefaultHttp2FrameWriter)1 DefaultHttp2RemoteFlowController (io.netty.handler.codec.http2.DefaultHttp2RemoteFlowController)1 Http2Connection (io.netty.handler.codec.http2.Http2Connection)1 Http2FrameReader (io.netty.handler.codec.http2.Http2FrameReader)1 Http2FrameWriter (io.netty.handler.codec.http2.Http2FrameWriter)1 Http2Settings (io.netty.handler.codec.http2.Http2Settings)1