use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.
the class NettyServerHandler method newHandler.
@VisibleForTesting
static NettyServerHandler newHandler(Http2FrameReader frameReader, Http2FrameWriter frameWriter, ServerTransportListener transportListener, int maxStreams, int flowControlWindow, int maxHeaderListSize, int maxMessageSize) {
Preconditions.checkArgument(maxStreams > 0, "maxStreams must be positive");
Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
Preconditions.checkArgument(maxMessageSize > 0, "maxMessageSize must be positive");
Http2Connection connection = new DefaultHttp2Connection(true);
// Create the local flow controller configured to auto-refill the connection window.
connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(connection, frameWriter);
// TODO(ejona): swap back to DefaultHttp2Connection with Netty-4.1.9
Http2ConnectionDecoder decoder = new FixedHttp2ConnectionDecoder(connection, encoder, frameReader);
Http2Settings settings = new Http2Settings();
settings.initialWindowSize(flowControlWindow);
settings.maxConcurrentStreams(maxStreams);
settings.maxHeaderListSize(maxHeaderListSize);
return new NettyServerHandler(transportListener, decoder, encoder, settings, maxMessageSize);
}
use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.
the class NettyClientHandler method newHandler.
@VisibleForTesting
static NettyClientHandler newHandler(Http2Connection connection, Http2FrameReader frameReader, Http2FrameWriter frameWriter, ClientTransportLifecycleManager lifecycleManager, KeepAliveManager keepAliveManager, int flowControlWindow, int maxHeaderListSize, Ticker ticker) {
Preconditions.checkNotNull(connection, "connection");
Preconditions.checkNotNull(frameReader, "frameReader");
Preconditions.checkNotNull(lifecycleManager, "lifecycleManager");
Preconditions.checkArgument(flowControlWindow > 0, "flowControlWindow must be positive");
Preconditions.checkArgument(maxHeaderListSize > 0, "maxHeaderListSize must be positive");
Preconditions.checkNotNull(ticker, "ticker");
Http2FrameLogger frameLogger = new Http2FrameLogger(LogLevel.DEBUG, NettyClientHandler.class);
frameReader = new Http2InboundFrameLogger(frameReader, frameLogger);
frameWriter = new Http2OutboundFrameLogger(frameWriter, frameLogger);
StreamBufferingEncoder encoder = new StreamBufferingEncoder(new DefaultHttp2ConnectionEncoder(connection, frameWriter));
// Create the local flow controller configured to auto-refill the connection window.
connection.local().flowController(new DefaultHttp2LocalFlowController(connection, DEFAULT_WINDOW_UPDATE_RATIO, true));
// TODO(ejona): swap back to DefaultHttp2Connection with Netty-4.1.9
Http2ConnectionDecoder decoder = new FixedHttp2ConnectionDecoder(connection, encoder, frameReader);
Http2Settings settings = new Http2Settings();
settings.pushEnabled(false);
settings.initialWindowSize(flowControlWindow);
settings.maxConcurrentStreams(0);
settings.maxHeaderListSize(maxHeaderListSize);
return new NettyClientHandler(decoder, encoder, settings, lifecycleManager, keepAliveManager, ticker);
}
use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.
the class NettyHandlerTestBase method serializeSettings.
protected final ByteBuf serializeSettings(Http2Settings settings) {
ChannelHandlerContext ctx = newMockContext();
new DefaultHttp2FrameWriter().writeSettings(ctx, settings, newPromise());
return captureWrite(ctx);
}
use of io.netty.handler.codec.http2.Http2Settings 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);
}
use of io.netty.handler.codec.http2.Http2Settings in project grpc-java by grpc.
the class NettyClientHandlerTest method setUp.
/**
* Set up for test.
*/
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
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(), DEFAULT_MAX_MESSAGE_SIZE);
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);
}
Aggregations