void HandleHttpRequest(IChannelHandlerContext ctx, IFullHttpRequest req)
 {
     // Handle a bad request.
     if (!req.Result.IsSuccess)
     {
         SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, BadRequest));
         return;
     }
     if ("/favicon.ico".Equals(req.Uri))
     {
         var res = new DefaultFullHttpResponse(Http11, NotFound);
         SendHttpResponse(ctx, req, res);
         return;
     }
     if (iJT1078Authorization.Authorization(req, out var principal))
     {
         if (req.Uri.StartsWith(WebsocketPath))
         {
             // Handshake
             var wsFactory = new WebSocketServerHandshakerFactory(GetWebSocketLocation(req), null, true, 5 * 1024 * 1024);
             this.handshaker = wsFactory.NewHandshaker(req);
             if (this.handshaker == null)
             {
                 WebSocketServerHandshakerFactory.SendUnsupportedVersionResponse(ctx.Channel);
             }
             else
             {
                 this.handshaker.HandshakeAsync(ctx.Channel, req);
                 jT1078HttpSessionManager.TryAdd(principal.Identity.Name, ctx.Channel);
                 httpMiddleware?.Next(ctx, req, principal);
             }
         }
         else
         {
             jT1078HttpSessionManager.TryAdd(principal.Identity.Name, ctx.Channel);
             httpMiddleware?.Next(ctx, req, principal);
         }
     }
     else
     {
         SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, Unauthorized));
         return;
     }
 }