DotNetty.Codecs.Http.WebSockets.WebSocketServerHandshakerFactory.SendUnsupportedVersionResponse C# (CSharp) Method

SendUnsupportedVersionResponse() public static method

Return that we need cannot not support the web socket version
public static SendUnsupportedVersionResponse ( IChannel channel ) : Task
channel IChannel
return Task
        public static Task SendUnsupportedVersionResponse(IChannel channel)
        {
            var res = new DefaultFullHttpResponse(
                HttpVersion.Http11,
                HttpResponseStatus.UpgradeRequired,
                channel.Allocator.Buffer(0));
            _ = res.Headers.Set(HttpHeaderNames.SecWebsocketVersion, WebSocketVersion.V13.ToHttpHeaderValue());
            HttpUtil.SetContentLength(res, 0);
            return channel.WriteAndFlushAsync(res);
        }
    }

Usage Example

        public override void ChannelRead(IChannelHandlerContext ctx, object msg)
        {
            var req = (IFullHttpRequest)msg;

            if (this.IsNotWebSocketPath(req))
            {
                ctx.FireChannelRead(msg);
                return;
            }

            try
            {
                if (!Equals(req.Method, Get))
                {
                    SendHttpResponse(ctx, req, new DefaultFullHttpResponse(Http11, Forbidden));
                    return;
                }

                var wsFactory = new WebSocketServerHandshakerFactory(
                    GetWebSocketLocation(ctx.Channel.Pipeline, req, this.websocketPath), this.subprotocols,
                    this.allowExtensions, this.maxFramePayloadSize, this.allowMaskMismatch);
                WebSocketServerHandshaker handshaker = wsFactory.NewHandshaker(req);
                if (handshaker == null)
                {
                    WebSocketServerHandshakerFactory.SendUnsupportedVersionResponse(ctx.Channel);
                }
                else
                {
                    Task task = handshaker.HandshakeAsync(ctx.Channel, req);
                    task.ContinueWith(t =>
                    {
                        if (t.Status != TaskStatus.RanToCompletion)
                        {
                            ctx.FireExceptionCaught(t.Exception);
                        }
                        else
                        {
                            ctx.FireUserEventTriggered(new WebSocketServerProtocolHandler.HandshakeComplete(
                                                           req.Uri, req.Headers, handshaker.SelectedSubprotocol));
                        }
                    },
                                      TaskContinuationOptions.ExecuteSynchronously);

                    WebSocketServerProtocolHandler.SetHandshaker(ctx.Channel, handshaker);
                    ctx.Channel.Pipeline.Replace(this, "WS403Responder",
                                                 WebSocketServerProtocolHandler.ForbiddenHttpRequestResponder());
                }
            }
            finally
            {
                req.Release();
            }
        }
All Usage Examples Of DotNetty.Codecs.Http.WebSockets.WebSocketServerHandshakerFactory::SendUnsupportedVersionResponse