diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConfig.java b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConfig.java index 8788551a1a..105b92a5e8 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConfig.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/client/HttpClientConfig.java @@ -867,27 +867,31 @@ static final class H2OrHttp11Codec extends ChannelInboundHandlerAdapter { @Override public void channelActive(ChannelHandlerContext ctx) { - SslHandler sslHandler = ctx.pipeline().get(SslHandler.class); - if (sslHandler == null) { - throw new IllegalStateException("Cannot determine negotiated application-level protocol."); - } - String protocol = sslHandler.applicationProtocol() != null ? sslHandler.applicationProtocol() : ApplicationProtocolNames.HTTP_1_1; - if (log.isDebugEnabled()) { - log.debug(format(ctx.channel(), "Negotiated application-level protocol [" + protocol + "]")); - } - if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { - configureHttp2Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, http2Settings, observer); - } - else if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) { - configureHttp11Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, metricsRecorder, uriTagValue); + ChannelHandler handler = ctx.pipeline().get(NettyPipeline.SslHandler); + if (handler instanceof SslHandler) { + SslHandler sslHandler = (SslHandler) handler; + + String protocol = sslHandler.applicationProtocol() != null ? sslHandler.applicationProtocol() : ApplicationProtocolNames.HTTP_1_1; + if (log.isDebugEnabled()) { + log.debug(format(ctx.channel(), "Negotiated application-level protocol [" + protocol + "]")); + } + if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { + configureHttp2Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, http2Settings, observer); + } + else if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) { + configureHttp11Pipeline(ctx.channel().pipeline(), acceptGzip, decoder, metricsRecorder, uriTagValue); + } + else { + throw new IllegalStateException("unknown protocol: " + protocol); + } + + ctx.fireChannelActive(); + + ctx.channel().pipeline().remove(this); } else { - throw new IllegalStateException("unknown protocol: " + protocol); + throw new IllegalStateException("Cannot determine negotiated application-level protocol."); } - - ctx.fireChannelActive(); - - ctx.channel().pipeline().remove(this); } }