Search in sources :

Example 1 with HTTP2_CONNECTION

use of software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.HTTP2_CONNECTION in project aws-sdk-java-v2 by aws.

the class ChannelPipelineInitializer method configureHttp2.

private void configureHttp2(Channel ch, ChannelPipeline pipeline) {
    // Using Http2FrameCodecBuilder and Http2MultiplexHandler based on 4.1.37 release notes
    // https://netty.io/news/2019/06/28/4-1-37-Final.html
    Http2FrameCodec codec = Http2FrameCodecBuilder.forClient().headerSensitivityDetector((name, value) -> lowerCase(name.toString()).equals("authorization")).initialSettings(Http2Settings.defaultSettings().initialWindowSize(clientInitialWindowSize)).frameLogger(new Http2FrameLogger(LogLevel.DEBUG)).build();
    // Connection listeners have higher priority than handlers, in the eyes of the Http2FrameCodec. The Http2FrameCodec will
    // close any connections when a GOAWAY is received, but we'd like to send a "GOAWAY happened" exception instead of just
    // closing the connection. Because of this, we use a go-away listener instead of a handler, so that we can send the
    // exception before the Http2FrameCodec closes the connection itself.
    codec.connection().addListener(new Http2GoAwayEventListener(ch));
    pipeline.addLast(codec);
    ch.attr(HTTP2_CONNECTION).set(codec.connection());
    ch.attr(HTTP2_INITIAL_WINDOW_SIZE).set(clientInitialWindowSize);
    pipeline.addLast(new Http2MultiplexHandler(new NoOpChannelInitializer()));
    pipeline.addLast(new Http2SettingsFrameHandler(ch, clientMaxStreams, channelPoolRef));
    if (healthCheckPingPeriod == null) {
        pipeline.addLast(new Http2PingHandler(HTTP2_CONNECTION_PING_TIMEOUT_SECONDS * 1_000));
    } else if (healthCheckPingPeriod.toMillis() > 0) {
        pipeline.addLast(new Http2PingHandler(saturatedCast(healthCheckPingPeriod.toMillis())));
    }
}
Also used : UnpooledByteBufAllocator(io.netty.buffer.UnpooledByteBufAllocator) NettyUtils.newSslHandler(software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils.newSslHandler) ChannelOption(io.netty.channel.ChannelOption) LoggingHandler(io.netty.handler.logging.LoggingHandler) Http2GoAwayEventListener(software.amazon.awssdk.http.nio.netty.internal.http2.Http2GoAwayEventListener) Protocol(software.amazon.awssdk.http.Protocol) Http2SettingsFrameHandler(software.amazon.awssdk.http.nio.netty.internal.http2.Http2SettingsFrameHandler) CompletableFuture(java.util.concurrent.CompletableFuture) Http2FrameCodecBuilder(io.netty.handler.codec.http2.Http2FrameCodecBuilder) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) HTTP2_CONNECTION_PING_TIMEOUT_SECONDS(software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration.HTTP2_CONNECTION_PING_TIMEOUT_SECONDS) HTTP2_INITIAL_WINDOW_SIZE(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.HTTP2_INITIAL_WINDOW_SIZE) NumericUtils.saturatedCast(software.amazon.awssdk.utils.NumericUtils.saturatedCast) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) Duration(java.time.Duration) URI(java.net.URI) StringUtils.lowerCase(software.amazon.awssdk.utils.StringUtils.lowerCase) ChannelInitializer(io.netty.channel.ChannelInitializer) SslContext(io.netty.handler.ssl.SslContext) CHANNEL_DIAGNOSTICS(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.CHANNEL_DIAGNOSTICS) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec) ChannelPipeline(io.netty.channel.ChannelPipeline) HTTP2_CONNECTION(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.HTTP2_CONNECTION) Channel(io.netty.channel.Channel) Http2Settings(io.netty.handler.codec.http2.Http2Settings) PROTOCOL_FUTURE(software.amazon.awssdk.http.nio.netty.internal.ChannelAttributeKey.PROTOCOL_FUTURE) SslProvider(io.netty.handler.ssl.SslProvider) AbstractChannelPoolHandler(io.netty.channel.pool.AbstractChannelPoolHandler) LogLevel(io.netty.handler.logging.LogLevel) SslHandler(io.netty.handler.ssl.SslHandler) Http2PingHandler(software.amazon.awssdk.http.nio.netty.internal.http2.Http2PingHandler) ChannelPool(io.netty.channel.pool.ChannelPool) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) Http2MultiplexHandler(io.netty.handler.codec.http2.Http2MultiplexHandler) Http2SettingsFrameHandler(software.amazon.awssdk.http.nio.netty.internal.http2.Http2SettingsFrameHandler) Http2GoAwayEventListener(software.amazon.awssdk.http.nio.netty.internal.http2.Http2GoAwayEventListener) Http2FrameLogger(io.netty.handler.codec.http2.Http2FrameLogger) Http2PingHandler(software.amazon.awssdk.http.nio.netty.internal.http2.Http2PingHandler) Http2FrameCodec(io.netty.handler.codec.http2.Http2FrameCodec)

Aggregations

UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)1 Channel (io.netty.channel.Channel)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOption (io.netty.channel.ChannelOption)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 AbstractChannelPoolHandler (io.netty.channel.pool.AbstractChannelPoolHandler)1 ChannelPool (io.netty.channel.pool.ChannelPool)1 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)1 Http2FrameCodec (io.netty.handler.codec.http2.Http2FrameCodec)1 Http2FrameCodecBuilder (io.netty.handler.codec.http2.Http2FrameCodecBuilder)1 Http2FrameLogger (io.netty.handler.codec.http2.Http2FrameLogger)1 Http2MultiplexHandler (io.netty.handler.codec.http2.Http2MultiplexHandler)1 Http2Settings (io.netty.handler.codec.http2.Http2Settings)1 LogLevel (io.netty.handler.logging.LogLevel)1 LoggingHandler (io.netty.handler.logging.LoggingHandler)1 SslContext (io.netty.handler.ssl.SslContext)1 SslHandler (io.netty.handler.ssl.SslHandler)1 SslProvider (io.netty.handler.ssl.SslProvider)1 URI (java.net.URI)1 Duration (java.time.Duration)1