在netty 中添加自带的 SslHandler 就能支持HTTPS,但是添加之后使用 HTTP 访问是存在问题的。
请问如何能支持使用用一个端口两种协议并行,比如在某个事件中判断出使用 HTTPS 协议然后在把 SslHandler 添加到 pipeline 中。
SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
SSLEngine sslEngine = sslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
ch.pipeline().addFirst( new SslHandler(sslEngine));
让同一个端口监听两种不同的协议,这本身是一个不好的设计,一般
80
端口提供HTTP
协议,443
端口提供HTTPS
协议。不过Netty
已经提供了同一个端口支持SSL
和non-SSL
的工具类OptionalSslHandler
。参考一下:https://github.com/netty/nett...