io.netty.handler.codec.http2.Http2Settings Java Examples
The following examples show how to use
io.netty.handler.codec.http2.Http2Settings.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractNettyHandler.java From grpc-java with Apache License 2.0 | 6 votes |
AbstractNettyHandler( ChannelPromise channelUnused, Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings, boolean autoFlowControl) { super(channelUnused, decoder, encoder, initialSettings); // During a graceful shutdown, wait until all streams are closed. gracefulShutdownTimeoutMillis(GRACEFUL_SHUTDOWN_NO_TIMEOUT); // Extract the connection window from the settings if it was set. this.initialConnectionWindow = initialSettings.initialWindowSize() == null ? -1 : initialSettings.initialWindowSize(); this.autoTuneFlowControlOn = autoFlowControl; if (encoder instanceof ListeningEncoder) { ((ListeningEncoder) encoder).setListener(pingCountingListener); } }
Example #2
Source File: NettyServerHandlerTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@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); }
Example #3
Source File: AbstractNettyHandler.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
public void updateWindow() throws Http2Exception { if (!autoTuneFlowControlOn) { return; } pingReturn++; long elapsedTime = (System.nanoTime() - lastPingTime); if (elapsedTime == 0) { elapsedTime = 1; } long bandwidth = (getDataSincePing() * TimeUnit.SECONDS.toNanos(1)) / elapsedTime; Http2LocalFlowController fc = decoder().flowController(); // Calculate new window size by doubling the observed BDP, but cap at max window int targetWindow = Math.min(getDataSincePing() * 2, MAX_WINDOW_SIZE); setPinging(false); int currentWindow = fc.initialWindowSize(connection().connectionStream()); if (targetWindow > currentWindow && bandwidth > lastBandwidth) { lastBandwidth = bandwidth; int increase = targetWindow - currentWindow; fc.incrementWindowSize(connection().connectionStream(), increase); fc.initialWindowSize(targetWindow); Http2Settings settings = new Http2Settings(); settings.initialWindowSize(targetWindow); frameWriter().writeSettings(ctx(), settings, ctx().newPromise()); } }
Example #4
Source File: AbstractNettyHandler.java From grpc-java with Apache License 2.0 | 6 votes |
public void updateWindow() throws Http2Exception { if (!autoTuneFlowControlOn) { return; } pingReturn++; long elapsedTime = (System.nanoTime() - lastPingTime); if (elapsedTime == 0) { elapsedTime = 1; } long bandwidth = (getDataSincePing() * TimeUnit.SECONDS.toNanos(1)) / elapsedTime; Http2LocalFlowController fc = decoder().flowController(); // Calculate new window size by doubling the observed BDP, but cap at max window int targetWindow = Math.min(getDataSincePing() * 2, MAX_WINDOW_SIZE); setPinging(false); int currentWindow = fc.initialWindowSize(connection().connectionStream()); if (targetWindow > currentWindow && bandwidth > lastBandwidth) { lastBandwidth = bandwidth; int increase = targetWindow - currentWindow; fc.incrementWindowSize(connection().connectionStream(), increase); fc.initialWindowSize(targetWindow); Http2Settings settings = new Http2Settings(); settings.initialWindowSize(targetWindow); frameWriter().writeSettings(ctx(), settings, ctx().newPromise()); } }
Example #5
Source File: Http2OrHttpHandler.java From zuul with Apache License 2.0 | 6 votes |
private void configureHttp2(ChannelPipeline pipeline) { // setup the initial stream settings for the server to use. Http2Settings settings = new Http2Settings() .maxConcurrentStreams(maxConcurrentStreams) .initialWindowSize(initialWindowSize) .headerTableSize(maxHeaderTableSize) .maxHeaderListSize(maxHeaderListSize); Http2FrameCodec frameCodec = Http2FrameCodecBuilder.forServer() .frameLogger(FRAME_LOGGER) .initialSettings(settings) .validateHeaders(true) .build(); Http2MultiplexHandler multiplexHandler = new Http2MultiplexHandler(http2StreamHandler); // The frame codec MUST be in the pipeline. pipeline.addBefore("codec_placeholder", /* name= */ null, frameCodec); pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexHandler); }
Example #6
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
static void configureHttp2Pipeline(ChannelPipeline p, HttpResponseDecoderSpec decoder, Http2Settings http2Settings, ConnectionObserver observer) { Http2FrameCodecBuilder http2FrameCodecBuilder = Http2FrameCodecBuilder.forClient() .validateHeaders(decoder.validateHeaders()) .initialSettings(http2Settings); if (p.get(NettyPipeline.LoggingHandler) != null) { http2FrameCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "reactor.netty.http.client.h2")); } p.addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.HttpCodec, http2FrameCodecBuilder.build()) .addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(new H2Codec())) .addBefore(NettyPipeline.ReactiveBridge, NettyPipeline.HttpTrafficHandler, new HttpTrafficHandler(observer)); }
Example #7
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
static void configureH2Pipeline(ChannelPipeline p, ServerCookieDecoder cookieDecoder, ServerCookieEncoder cookieEncoder, boolean forwarded, Http2Settings http2Settings, ConnectionObserver listener, ChannelOperations.OnSetup opsFactory, boolean validate) { p.remove(NettyPipeline.ReactiveBridge); Http2FrameCodecBuilder http2FrameCodecBuilder = Http2FrameCodecBuilder.forServer() .validateHeaders(validate) .initialSettings(http2Settings); if (p.get(NettyPipeline.LoggingHandler) != null) { http2FrameCodecBuilder.frameLogger(new Http2FrameLogger(LogLevel.DEBUG, "reactor.netty.http.server.h2")); } p.addLast(NettyPipeline.HttpCodec, http2FrameCodecBuilder.build()) .addLast(NettyPipeline.H2MultiplexHandler, new Http2MultiplexHandler(new H2Codec(opsFactory, listener, forwarded, cookieEncoder, cookieDecoder))); }
Example #8
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
Http11OrH2CleartextCodec( ServerCookieDecoder cookieDecoder, ServerCookieEncoder cookieEncoder, boolean debug, boolean forwarded, Http2Settings http2Settings, ConnectionObserver listener, ChannelOperations.OnSetup opsFactory, boolean validate) { this.cookieDecoder = cookieDecoder; this.cookieEncoder = cookieEncoder; this.forwarded = forwarded; Http2FrameCodecBuilder http2FrameCodecBuilder = Http2FrameCodecBuilder.forServer() .validateHeaders(validate) .initialSettings(http2Settings); if (debug) { http2FrameCodecBuilder.frameLogger(new Http2FrameLogger( LogLevel.DEBUG, "reactor.netty.http.server.h2")); } this.http2FrameCodec = http2FrameCodecBuilder.build(); this.listener = listener; this.opsFactory = opsFactory; }
Example #9
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 6 votes |
H2OrHttp11Codec( @Nullable BiPredicate<HttpServerRequest, HttpServerResponse> compressPredicate, ServerCookieDecoder cookieDecoder, ServerCookieEncoder cookieEncoder, HttpRequestDecoderSpec decoder, boolean forwarded, Http2Settings http2Settings, ConnectionObserver listener, @Nullable Supplier<? extends ChannelMetricsRecorder> metricsRecorder, int minCompressionSize, ChannelOperations.OnSetup opsFactory, @Nullable Function<String, String> uriTagValue) { super(ApplicationProtocolNames.HTTP_1_1); this.compressPredicate = compressPredicate; this.cookieDecoder = cookieDecoder; this.cookieEncoder = cookieEncoder; this.decoder = decoder; this.forwarded = forwarded; this.http2Settings = http2Settings; this.listener = listener; this.metricsRecorder = metricsRecorder; this.minCompressionSize = minCompressionSize; this.opsFactory = opsFactory; this.uriTagValue = uriTagValue; }
Example #10
Source File: NettyServerHandlerTest.java From grpc-java with Apache License 2.0 | 6 votes |
@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); }
Example #11
Source File: HttpServerPipelineConfigurator.java From armeria with Apache License 2.0 | 6 votes |
private Http2Settings http2Settings() { final Http2Settings settings = new Http2Settings(); final int initialWindowSize = config.http2InitialStreamWindowSize(); if (initialWindowSize != Http2CodecUtil.DEFAULT_WINDOW_SIZE) { settings.initialWindowSize(initialWindowSize); } final int maxFrameSize = config.http2MaxFrameSize(); if (maxFrameSize != Http2CodecUtil.DEFAULT_MAX_FRAME_SIZE) { settings.maxFrameSize(maxFrameSize); } // Not using the value greater than 2^31-1 because some HTTP/2 client implementations use a signed // 32-bit integer to represent an HTTP/2 SETTINGS parameter value. settings.maxConcurrentStreams(Math.min(config.http2MaxStreamsPerConnection(), Integer.MAX_VALUE)); settings.maxHeaderListSize(config.http2MaxHeaderListSize()); return settings; }
Example #12
Source File: Http2ClientInitializer.java From jmeter-http2-plugin with Apache License 2.0 | 5 votes |
/** * write customized SETTINGS */ @Override public ChannelFuture writeSettings(ChannelHandlerContext ctx, Http2Settings settings, ChannelPromise promise) { if(this.settings != null) { return super.writeSettings(ctx, this.settings, promise); } else { return super.writeSettings(ctx, settings, promise); } }
Example #13
Source File: Http2SettingsHandler.java From jmeter-http2-plugin with Apache License 2.0 | 5 votes |
@Override protected void messageReceived(ChannelHandlerContext ctx, Http2Settings msg) throws Exception { promise.setSuccess(); // Only care about the first settings message ctx.pipeline().remove(this); }
Example #14
Source File: Http2SettingsHandler.java From http2-examples with Apache License 2.0 | 5 votes |
@Override protected void messageReceived(ChannelHandlerContext ctx, Http2Settings msg) throws Exception { promise.setSuccess(); // Only care about the first settings message ctx.pipeline().remove(this); }
Example #15
Source File: THttp2Client.java From armeria with Apache License 2.0 | 5 votes |
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2Settings) { settingsPromise.setSuccess(null); return; } if (msg instanceof FullHttpResponse) { final FullHttpResponse res = (FullHttpResponse) msg; final Integer streamId = res.headers().getInt( HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text()); if (streamId == null) { responsePromise.tryFailure(new AssertionError("message without stream ID: " + msg)); return; } if (streamId == 1) { // Response to the upgrade request, which is OK to ignore. return; } if (streamId != 3) { responsePromise.tryFailure(new AssertionError("unexpected stream ID: " + msg)); return; } responsePromise.setSuccess(res.content().retain()); return; } throw new IllegalStateException("unexpected message type: " + msg.getClass().getName()); }
Example #16
Source File: HttpClientPipelineConfigurator.java From armeria with Apache License 2.0 | 5 votes |
private Http2Settings http2Settings() { final Http2Settings settings = new Http2Settings(); final int initialWindowSize = clientFactory.http2InitialStreamWindowSize(); if (initialWindowSize != DEFAULT_WINDOW_SIZE) { settings.initialWindowSize(initialWindowSize); } final int maxFrameSize = clientFactory.http2MaxFrameSize(); if (maxFrameSize != DEFAULT_MAX_FRAME_SIZE) { settings.maxFrameSize(maxFrameSize); } settings.maxHeaderListSize(clientFactory.http2MaxHeaderListSize()); return settings; }
Example #17
Source File: NettyClientHandler.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Override public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings settings) { if (firstSettings) { firstSettings = false; lifecycleManager.notifyReady(); } }
Example #18
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
H2OrHttp11Codec( boolean acceptGzip, HttpResponseDecoderSpec decoder, Http2Settings http2Settings, @Nullable Supplier<? extends ChannelMetricsRecorder> metricsRecorder, ConnectionObserver observer, @Nullable Function<String, String> uriTagValue) { this.acceptGzip = acceptGzip; this.decoder = decoder; this.http2Settings = http2Settings; this.metricsRecorder = metricsRecorder; this.observer = observer; this.uriTagValue = uriTagValue; }
Example #19
Source File: NettyServerHandlerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void shouldAdvertiseMaxHeaderListSize() throws Exception { maxHeaderListSize = 123; manualSetUp(); ArgumentCaptor<Http2Settings> captor = ArgumentCaptor.forClass(Http2Settings.class); verifyWrite().writeSettings( any(ChannelHandlerContext.class), captor.capture(), any(ChannelPromise.class)); assertEquals(maxHeaderListSize, captor.getValue().maxHeaderListSize().intValue()); }
Example #20
Source File: AbstractNettyHandler.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
AbstractNettyHandler( ChannelPromise channelUnused, Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) { super(channelUnused, decoder, encoder, initialSettings); // During a graceful shutdown, wait until all streams are closed. gracefulShutdownTimeoutMillis(GRACEFUL_SHUTDOWN_NO_TIMEOUT); // Extract the connection window from the settings if it was set. this.initialConnectionWindow = initialSettings.initialWindowSize() == null ? -1 : initialSettings.initialWindowSize(); }
Example #21
Source File: NettyServerHandlerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@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)); }
Example #22
Source File: HttpClientConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
Http2Settings http2Settings() { Http2Settings settings = Http2Settings.defaultSettings(); if (http2Settings != null) { Long headerTableSize = http2Settings.headerTableSize(); if (headerTableSize != null) { settings.headerTableSize(headerTableSize); } Integer initialWindowSize = http2Settings.initialWindowSize(); if (initialWindowSize != null) { settings.initialWindowSize(initialWindowSize); } Long maxConcurrentStreams = http2Settings.maxConcurrentStreams(); if (maxConcurrentStreams != null) { settings.maxConcurrentStreams(maxConcurrentStreams); } Integer maxFrameSize = http2Settings.maxFrameSize(); if (maxFrameSize != null) { settings.maxFrameSize(maxFrameSize); } settings.maxHeaderListSize(http2Settings.maxHeaderListSize()); Boolean pushEnabled = http2Settings.pushEnabled(); if (pushEnabled != null) { settings.pushEnabled(pushEnabled); } } return settings; }
Example #23
Source File: ProtocolNegotiatorsTest.java From grpc-java with Apache License 2.0 | 5 votes |
FakeGrpcHttp2ConnectionHandler(ChannelPromise channelUnused, Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings, boolean noop) { super(channelUnused, decoder, encoder, initialSettings); this.noop = noop; }
Example #24
Source File: HttpSessionHandler.java From armeria with Apache License 2.0 | 5 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2Settings) { final Long maxConcurrentStreams = ((Http2Settings) msg).maxConcurrentStreams(); if (maxConcurrentStreams != null) { maxUnfinishedResponses = maxConcurrentStreams > Integer.MAX_VALUE ? Integer.MAX_VALUE : maxConcurrentStreams.intValue(); } else { maxUnfinishedResponses = Integer.MAX_VALUE; } return; } // Handle an unexpected message by raising an exception with debugging information. try { final String typeInfo; if (msg instanceof ByteBuf) { typeInfo = msg + " HexDump: " + ByteBufUtil.hexDump((ByteBuf) msg); } else { typeInfo = String.valueOf(msg); } throw new IllegalStateException("unexpected message type: " + typeInfo + " (expected: ByteBuf)"); } finally { ReferenceCountUtil.release(msg); } }
Example #25
Source File: Http2ClientConnectionHandlerBuilder.java From armeria with Apache License 2.0 | 5 votes |
@Override protected Http2ClientConnectionHandler build(Http2ConnectionDecoder decoder, Http2ConnectionEncoder encoder, Http2Settings initialSettings) throws Exception { return new Http2ClientConnectionHandler( decoder, encoder, initialSettings, channel(), clientFactory, protocol); }
Example #26
Source File: HttpServerHandler.java From armeria with Apache License 2.0 | 5 votes |
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { isReading = true; // Cleared in channelReadComplete() if (msg instanceof Http2Settings) { handleHttp2Settings(ctx, (Http2Settings) msg); } else { handleRequest(ctx, (DecodedHttpRequest) msg); } }
Example #27
Source File: Http2SettingsFrameHandlerTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
private Http2SettingsFrame http2SettingsFrame(long serverMaxStreams) { return new Http2SettingsFrame() { @Override public Http2Settings settings() { Http2Settings http2Settings = new Http2Settings(); http2Settings.maxConcurrentStreams(serverMaxStreams); return http2Settings; } @Override public String name() { return "test"; } }; }
Example #28
Source File: Http2TestUtils.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
public static EmbeddedChannel newHttp2Channel(ChannelHandler channelHandler) { Http2FrameCodec http2FrameCodec = Http2FrameCodecBuilder.forClient().initialSettings( Http2Settings.defaultSettings().initialWindowSize(INITIAL_WINDOW_SIZE)) .frameLogger(new Http2FrameLogger(LogLevel.DEBUG)).build(); EmbeddedChannel channel = new EmbeddedChannel(http2FrameCodec, new Http2MultiplexHandler(channelHandler)); channel.attr(ChannelAttributeKey.HTTP2_CONNECTION).set(http2FrameCodec.connection()); channel.attr(ChannelAttributeKey.HTTP2_INITIAL_WINDOW_SIZE).set(INITIAL_WINDOW_SIZE); channel.attr(ChannelAttributeKey.PROTOCOL_FUTURE).set(CompletableFuture.completedFuture(Protocol.HTTP2)); return channel; }
Example #29
Source File: WindowSizeTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override protected void initChannel(SocketChannel ch) { Http2FrameCodec codec = Http2FrameCodecBuilder.forServer() .initialSettings(new Http2Settings() .maxConcurrentStreams(5)) .build(); ch.pipeline().addLast(codec); ch.pipeline().addLast(handlerSupplier.get()); }
Example #30
Source File: HttpServerConfig.java From reactor-netty with Apache License 2.0 | 5 votes |
Http2Settings http2Settings() { Http2Settings settings = Http2Settings.defaultSettings(); if (http2Settings != null) { Long headerTableSize = http2Settings.headerTableSize(); if (headerTableSize != null) { settings.headerTableSize(headerTableSize); } Integer initialWindowSize = http2Settings.initialWindowSize(); if (initialWindowSize != null) { settings.initialWindowSize(initialWindowSize); } Long maxConcurrentStreams = http2Settings.maxConcurrentStreams(); if (maxConcurrentStreams != null) { settings.maxConcurrentStreams(maxConcurrentStreams); } Integer maxFrameSize = http2Settings.maxFrameSize(); if (maxFrameSize != null) { settings.maxFrameSize(maxFrameSize); } settings.maxHeaderListSize(http2Settings.maxHeaderListSize()); Boolean pushEnabled = http2Settings.pushEnabled(); if (pushEnabled != null) { settings.pushEnabled(pushEnabled); } } return settings; }