在 集成 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());
}
即可
