Beispiel #1
0
        public async Task InvokeAsync(HttpContext context)
        {
            if (context.Request.Path == "/ws")
            {
                if (context.WebSockets.IsWebSocketRequest)
                {
                    var webSocket = await context.WebSockets.AcceptWebSocketAsync();

                    var socketFinishedTcs = new TaskCompletionSource <object>();

                    await _requestHandler.Handle(webSocket, socketFinishedTcs);

                    await socketFinishedTcs.Task;

                    await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Response sent", CancellationToken.None);
                }
                else
                {
                    context.Response.StatusCode = 400;
                }
            }
            else
            {
                await _next(context);
            }
        }
        public async Task Invoke(HttpContext context)
        {
            if (context.WebSockets.IsWebSocketRequest)
            {
                WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();

                await _handler.Handle(context, webSocket);
            }

            // Call the next delegate/middleware in the pipeline
            await _next(context);
        }