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());
}

 

即可

posted on 2018-01-31 11:16  yaolunhui  阅读(2703)  评论(0编辑  收藏  举报

导航