如何让 netty 同时支持HTTP与HTTPS

在netty中添加自带的SslHandler就能支持HTTPS,但是添加之后使用HTTP访问是存在问题的。请问如何能支持使用用一个端口两种协议并行,比如在某个事件中判断出使用HTTPS协议然后在把SslHandler添加到pipeline中。
SelfSignedCertificatessc=newSelfSignedCertificate();
SslContextsslCtx=SslContextBuilder.forServer(ssc.certificate(),ssc.privateKey()).build();
SSLEnginesslEngine=sslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
ch.pipeline().addFirst(newSslHandler(sslEngine));
白板的微信
浏览 1705回答 3
3回答

高慧超

实例发一下, 结合两位的答案, 完美一个服务处理两种请求SelfSignedCertificate ssc=new SelfSignedCertificate(); SslContext sslCtx= SslContextBuilder.forServer(ssc.certificate(),ssc.privateKey()).build(); pipeline.addFirst(new OptionalSslHandler(sslCtx));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript