use of io.netty.handler.codec.http2.Http2HeadersDecoder 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("[]");
}
use of io.netty.handler.codec.http2.Http2HeadersDecoder 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")));
}
use of io.netty.handler.codec.http2.Http2HeadersDecoder in project grpc-java by grpc.
the class NettyHandlerTestBase method initChannel.
/**
* Must be called by subclasses to initialize the handler and channel.
*/
protected final void initChannel(Http2HeadersDecoder headersDecoder) throws Exception {
content = Unpooled.copiedBuffer("hello world", UTF_8);
frameWriter = mock(Http2FrameWriter.class, delegatesTo(new DefaultHttp2FrameWriter()));
frameReader = new DefaultHttp2FrameReader(headersDecoder);
channel = new FakeClockSupportedChanel();
handler = newHandler();
channel.pipeline().addLast(handler);
ctx = channel.pipeline().context(handler);
writeQueue = initWriteQueue();
}
use of io.netty.handler.codec.http2.Http2HeadersDecoder in project rest.li by linkedin.
the class Http2StreamCodecBuilder method build.
@Override
public Http2StreamCodec build() {
ObjectUtil.checkNotNull(_connection, "connection");
Http2HeadersDecoder headerDecoder = new DefaultHttp2HeadersDecoder(isValidateHeaders());
Http2FrameReader reader = new DefaultHttp2FrameReader(headerDecoder);
Http2FrameWriter writer = new DefaultHttp2FrameWriter(headerSensitivityDetector());
if (frameLogger() != null) {
reader = new Http2InboundFrameLogger(reader, frameLogger());
writer = new Http2OutboundFrameLogger(writer, frameLogger());
}
Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(_connection, writer);
boolean encoderEnforceMaxConcurrentStreams = encoderEnforceMaxConcurrentStreams();
if (encoderEnforceMaxConcurrentStreams) {
if (_connection.isServer()) {
encoder.close();
reader.close();
throw new IllegalArgumentException("encoderEnforceMaxConcurrentStreams: " + encoderEnforceMaxConcurrentStreams + " not supported for server");
}
encoder = new StreamBufferingEncoder(encoder);
}
_connection.local().flowController(new DefaultHttp2LocalFlowController(_connection, DEFAULT_WINDOW_UPDATE_RATIO, AUTO_REFILL_CONNECTION_WINDOW));
Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(_connection, encoder, reader);
super.codec(decoder, encoder);
return super.build();
}
use of io.netty.handler.codec.http2.Http2HeadersDecoder in project rest.li by linkedin.
the class Http2StreamCodecBuilder method build.
@Override
public Http2StreamCodec build() {
ObjectUtil.checkNotNull(_connection, "connection");
ObjectUtil.checkPositive(_maxHeaderSize, "maxHeaderSize");
Http2HeadersDecoder headerDecoder = new DefaultHttp2HeadersDecoder(_maxHeaderSize, Http2CodecUtil.DEFAULT_HEADER_TABLE_SIZE, isValidateHeaders(), INITIAL_HUFFMAN_DECODE_CAPACITY);
Http2FrameReader reader = new DefaultHttp2FrameReader(headerDecoder);
Http2FrameWriter writer = new DefaultHttp2FrameWriter(headerSensitivityDetector());
if (frameLogger() != null) {
reader = new Http2InboundFrameLogger(reader, frameLogger());
writer = new Http2OutboundFrameLogger(writer, frameLogger());
}
Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(_connection, writer);
boolean encoderEnforceMaxConcurrentStreams = encoderEnforceMaxConcurrentStreams();
if (encoderEnforceMaxConcurrentStreams) {
if (_connection.isServer()) {
encoder.close();
reader.close();
throw new IllegalArgumentException("encoderEnforceMaxConcurrentStreams: " + encoderEnforceMaxConcurrentStreams + " not supported for server");
}
encoder = new StreamBufferingEncoder(encoder);
}
Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(_connection, encoder, reader);
super.codec(decoder, encoder);
return super.build();
}
Aggregations