Search in sources :

Example 1 with GrpcHttp2ServerHeadersDecoder

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

the class GrpcHttp2HeadersUtilsTest method decode_requestHeaders.

@Test
public void decode_requestHeaders() throws Http2Exception {
    Http2HeadersDecoder decoder = new GrpcHttp2ServerHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
    Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
    Http2Headers headers = new DefaultHttp2Headers(false);
    headers.add(of(":scheme"), of("https")).add(of(":method"), of("GET")).add(of(":path"), of("index.html")).add(of(":authority"), of("foo.grpc.io")).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(":scheme")), decodedHeaders.scheme());
    assertEquals(headers.get(of(":method")), decodedHeaders.method());
    assertEquals(headers.get(of(":path")), decodedHeaders.path());
    assertEquals(headers.get(of(":authority")), decodedHeaders.authority());
    assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
    assertEquals(headers.size(), decodedHeaders.size());
    String toString = decodedHeaders.toString();
    assertContainsKeyAndValue(toString, ":scheme", decodedHeaders.scheme());
    assertContainsKeyAndValue(toString, ":method", decodedHeaders.method());
    assertContainsKeyAndValue(toString, ":path", decodedHeaders.path());
    assertContainsKeyAndValue(toString, ":authority", decodedHeaders.authority());
    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) GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2HeadersEncoder(io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder) Test(org.junit.Test)

Example 2 with GrpcHttp2ServerHeadersDecoder

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

the class NettyServerHandlerTest method transportReadyDelayedUntilConnectionPreface.

@Test
public void transportReadyDelayedUntilConnectionPreface() throws Exception {
    initChannel(new GrpcHttp2ServerHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
    handler().handleProtocolNegotiationCompleted(Attributes.EMPTY, /*securityInfo=*/
    null);
    verify(transportListener, never()).transportReady(any(Attributes.class));
    // Simulate receipt of the connection preface
    channelRead(Http2CodecUtil.connectionPrefaceBuf());
    channelRead(serializeSettings(new Http2Settings()));
    verify(transportListener).transportReady(any(Attributes.class));
}
Also used : GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder) Attributes(io.grpc.Attributes) Http2Settings(io.netty.handler.codec.http2.Http2Settings) Test(org.junit.Test)

Example 3 with GrpcHttp2ServerHeadersDecoder

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

the class NettyServerHandler method newHandler.

static NettyServerHandler newHandler(ServerTransportListener transportListener, ChannelPromise channelUnused, List<? extends ServerStreamTracer.Factory> streamTracerFactories, TransportTracer transportTracer, int maxStreams, boolean autoFlowControl, int flowControlWindow, int maxHeaderListSize, int maxMessageSize, long keepAliveTimeInNanos, long keepAliveTimeoutInNanos, long maxConnectionIdleInNanos, long maxConnectionAgeInNanos, long maxConnectionAgeGraceInNanos, boolean permitKeepAliveWithoutCalls, long permitKeepAliveTimeInNanos, Attributes eagAttributes) {
    Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive: %s", maxHeaderListSize);
    Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyServerHandler.class);
    Http2HeadersDecoder headersDecoder = new GrpcHttp2ServerHeadersDecoder(maxHeaderListSize);
    Http2FrameReader frameReader = new Http2InboundFrameLogger(new DefaultHttp2FrameReader(headersDecoder), frameLogger);
    Http2FrameWriter frameWriter = new Http2OutboundFrameLogger(new DefaultHttp2FrameWriter(), frameLogger);
    return newHandler(channelUnused, frameReader, frameWriter, transportListener, streamTracerFactories, transportTracer, maxStreams, autoFlowControl, flowControlWindow, maxHeaderListSize, maxMessageSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos, maxConnectionIdleInNanos, maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos, permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos, eagAttributes);
}
Also used : Http2InboundFrameLogger(io.netty.handler.codec.http2.Http2InboundFrameLogger) 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) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder) Http2OutboundFrameLogger(io.netty.handler.codec.http2.Http2OutboundFrameLogger) Http2HeadersDecoder(io.netty.handler.codec.http2.Http2HeadersDecoder) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter) DefaultHttp2FrameReader(io.netty.handler.codec.http2.DefaultHttp2FrameReader)

Example 4 with GrpcHttp2ServerHeadersDecoder

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

the class NettyServerHandlerTest method manualSetUp.

@Override
protected void manualSetUp() throws Exception {
    assertNull("manualSetUp should not run more than once", handler());
    initChannel(new GrpcHttp2ServerHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
    // replace the keepAliveManager with spyKeepAliveManager
    spyKeepAliveManager = mock(KeepAliveManager.class, delegatesTo(handler().getKeepAliveManagerForTest()));
    handler().setKeepAliveManagerForTest(spyKeepAliveManager);
    // Simulate receipt of the connection preface
    handler().handleProtocolNegotiationCompleted(Attributes.EMPTY, /*securityInfo=*/
    null);
    channelRead(Http2CodecUtil.connectionPrefaceBuf());
    // Simulate receipt of initial remote settings.
    ByteBuf serializedSettings = serializeSettings(new Http2Settings());
    channelRead(serializedSettings);
}
Also used : GrpcHttp2ServerHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) KeepAliveManager(io.grpc.internal.KeepAliveManager) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

GrpcHttp2ServerHeadersDecoder (io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ServerHeadersDecoder)4 Http2HeadersDecoder (io.netty.handler.codec.http2.Http2HeadersDecoder)2 Http2Settings (io.netty.handler.codec.http2.Http2Settings)2 Test (org.junit.Test)2 Attributes (io.grpc.Attributes)1 KeepAliveManager (io.grpc.internal.KeepAliveManager)1 ByteBuf (io.netty.buffer.ByteBuf)1 DecoratingHttp2FrameWriter (io.netty.handler.codec.http2.DecoratingHttp2FrameWriter)1 DefaultHttp2FrameReader (io.netty.handler.codec.http2.DefaultHttp2FrameReader)1 DefaultHttp2FrameWriter (io.netty.handler.codec.http2.DefaultHttp2FrameWriter)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1 DefaultHttp2HeadersEncoder (io.netty.handler.codec.http2.DefaultHttp2HeadersEncoder)1 Http2FrameLogger (io.netty.handler.codec.http2.Http2FrameLogger)1 Http2FrameReader (io.netty.handler.codec.http2.Http2FrameReader)1 Http2FrameWriter (io.netty.handler.codec.http2.Http2FrameWriter)1 Http2Headers (io.netty.handler.codec.http2.Http2Headers)1 Http2HeadersEncoder (io.netty.handler.codec.http2.Http2HeadersEncoder)1 Http2InboundFrameLogger (io.netty.handler.codec.http2.Http2InboundFrameLogger)1 Http2OutboundFrameLogger (io.netty.handler.codec.http2.Http2OutboundFrameLogger)1 AsciiString (io.netty.util.AsciiString)1