35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using System.Buffers;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Connections;
|
|
|
|
namespace Microsoft.AspNetCore.SignalR.Tests
|
|
{
|
|
[Authorize]
|
|
public class AuthConnectionHandler : ConnectionHandler
|
|
{
|
|
public override async Task OnConnectedAsync(ConnectionContext connection)
|
|
{
|
|
while (true)
|
|
{
|
|
var result = await connection.Transport.Input.ReadAsync();
|
|
var buffer = result.Buffer;
|
|
|
|
if (!buffer.IsEmpty)
|
|
{
|
|
await connection.Transport.Output.WriteAsync(buffer.ToArray());
|
|
}
|
|
else if (result.IsCompleted)
|
|
{
|
|
break;
|
|
}
|
|
|
|
connection.Transport.Input.AdvanceTo(buffer.End);
|
|
}
|
|
}
|
|
}
|
|
}
|