netty支持https


在 集成  ChannelInitializer<SocketChannel> 實現

File certificate = new File("/Users/wucao/Desktop/https/1_gw2.vsgames.cn_bundle.crt"); // 證書
File privateKey = new File("/Users/wucao/Desktop/https/private.pem"); // 私鑰
final SslContext sslContext = SslContextBuilder.forServer(certificate, privateKey).build();

protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();


// 加入SslHandler實現HTTPS
SslHandler sslHandler = sslContext.newHandler(ch.alloc());
pipeline.addLast(sslHandler);

pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("deflater", new HttpContentCompressor());
pipeline.addLast("handler", new HttpServerHandler());
}

 

即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM