在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));
3 回答

高慧超
TA贡献1条经验 获得超0个赞
实例发一下, 结合两位的答案, 完美一个服务处理两种请求
SelfSignedCertificate ssc=new SelfSignedCertificate(); SslContext sslCtx= SslContextBuilder.forServer(ssc.certificate(),ssc.privateKey()).build(); pipeline.addFirst(new OptionalSslHandler(sslCtx));
添加回答
举报
0/150
提交
取消