use of io.grpc.netty.GrpcHttp2HeadersDecoder.GrpcHttp2ServerHeadersDecoder in project grpc-java by grpc.
the class NettyServerHandler method newHandler.
static NettyServerHandler newHandler(ServerTransportListener transportListener, int maxStreams, int flowControlWindow, int maxHeaderListSize, int maxMessageSize) {
Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
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(frameReader, frameWriter, transportListener, maxStreams, flowControlWindow, maxHeaderListSize, maxMessageSize);
}
use of io.grpc.netty.GrpcHttp2HeadersDecoder.GrpcHttp2ServerHeadersDecoder in project grpc-java by grpc.
the class GrpcHttp2HeadersDecoderTest 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")));
}
use of io.grpc.netty.GrpcHttp2HeadersDecoder.GrpcHttp2ServerHeadersDecoder in project grpc-java by grpc.
the class NettyServerHandlerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
initChannel(new GrpcHttp2ServerHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
// Simulate receipt of the connection preface
handler().handleProtocolNegotiationCompleted(Attributes.EMPTY);
channelRead(Http2CodecUtil.connectionPrefaceBuf());
// Simulate receipt of initial remote settings.
ByteBuf serializedSettings = serializeSettings(new Http2Settings());
channelRead(serializedSettings);
}
Aggregations