content: package cn.xeblog.server.handler;
  
  import cn.xeblog.server.codec.WebSocketMessageEncoder;
  import io.netty.channel.ChannelInitializer;
  import io.netty.channel.socket.SocketChannel;
  import io.netty.handler.codec.http.HttpObjectAggregator;
  import io.netty.handler.codec.http.HttpServerCodec;
  import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
  import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
  import io.netty.handler.stream.ChunkedWriteHandler;
  import io.netty.handler.timeout.IdleStateHandler;
  
  /**
   * @author anlingyi
   * @date 2023/8/31 8:33 PM
   */
  public class HttpAndWebSocketChannelInitializer extends ChannelInitializer<SocketChannel> {
  
      @Override
      protected void initChannel(SocketChannel ch) throws Exception {
          ch.pipeline()
                  .addLast(new IdleStateHandler(0, 0, 60))
                  .addLast(new HttpServerCodec())
                  .addLast(new HttpObjectAggregator(65536))
                  .addLast(new ChunkedWriteHandler())
                  .addLast(new WebSocketMessageEncoder())
                  .addLast(new WebSocketServerCompressionHandler())
                  .addLast(new WebSocketServerProtocolHandler("/xechat", null, true))
                  .addLast(new HttpChannelHandler())
                  .addLast(new WebSocketChannelHandler());
      }
  
  }
  