The rename games part 1 of many (#1696)
- React to rename of EndPoint to ConnectionHandler - Rename UseSockets to UseConnections - Rename MapEndPoint to MapConnectionHandler - Rename HttpSocketOptions to HttpConnectionOptions
This commit is contained in:
parent
d367bdc9aa
commit
2e63e5afe3
|
|
@ -9,7 +9,7 @@ using System.Reactive.Linq;
|
|||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@
|
|||
<MicrosoftAspNetCoreHttpPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreHttpPackageVersion>
|
||||
<MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreIdentityEntityFrameworkCorePackageVersion>
|
||||
<MicrosoftAspNetCoreMvcPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreMvcPackageVersion>
|
||||
<MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion>
|
||||
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>2.1.0-a-preview2-bedrock-renames-17598</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
|
||||
<MicrosoftAspNetCoreRoutingPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreRoutingPackageVersion>
|
||||
<MicrosoftAspNetCoreServerIISIntegrationPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreServerIISIntegrationPackageVersion>
|
||||
<MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>0.5.0-preview2-30355</MicrosoftAspNetCoreServerIntegrationTestingPackageVersion>
|
||||
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreServerKestrelPackageVersion>
|
||||
<MicrosoftAspNetCoreServerKestrelPackageVersion>2.1.0-a-preview2-bedrock-renames-17598</MicrosoftAspNetCoreServerKestrelPackageVersion>
|
||||
<MicrosoftAspNetCoreStaticFilesPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreStaticFilesPackageVersion>
|
||||
<MicrosoftAspNetCoreTestHostPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreTestHostPackageVersion>
|
||||
<MicrosoftAspNetCoreTestingPackageVersion>2.1.0-preview2-30355</MicrosoftAspNetCoreTestingPackageVersion>
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@
|
|||
|
||||
using System.Buffers;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
||||
namespace FunctionalTests
|
||||
{
|
||||
public class EchoEndPoint : EndPoint
|
||||
public class EchoConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public async override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -23,7 +23,7 @@ namespace FunctionalTests
|
|||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSockets();
|
||||
services.AddConnections();
|
||||
services.AddSignalR()
|
||||
.AddJsonProtocol(options =>
|
||||
{
|
||||
|
|
@ -70,7 +70,6 @@ namespace FunctionalTests
|
|||
}
|
||||
};
|
||||
});
|
||||
services.AddSingleton<EchoEndPoint>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
|
|
@ -81,9 +80,9 @@ namespace FunctionalTests
|
|||
}
|
||||
|
||||
app.UseFileServer();
|
||||
app.UseSockets(routes =>
|
||||
app.UseConnections(routes =>
|
||||
{
|
||||
routes.MapEndPoint<EchoEndPoint>("/echo");
|
||||
routes.MapConnectionHandler<EchoConnectionHandler>("/echo");
|
||||
});
|
||||
|
||||
app.UseSignalR(routes =>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.Net.Http;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.Extensions.CommandLineUtils;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
||||
namespace SocialWeather
|
||||
|
|
|
|||
|
|
@ -4,21 +4,21 @@
|
|||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace SocialWeather
|
||||
{
|
||||
public class SocialWeatherEndPoint : EndPoint
|
||||
public class SocialWeatherConnectionHandler : ConnectionHandler
|
||||
{
|
||||
private readonly PersistentConnectionLifeTimeManager _lifetimeManager;
|
||||
private readonly FormatterResolver _formatterResolver;
|
||||
private readonly ILogger<SocialWeatherEndPoint> _logger;
|
||||
private readonly ILogger<SocialWeatherConnectionHandler> _logger;
|
||||
|
||||
public SocialWeatherEndPoint(PersistentConnectionLifeTimeManager lifetimeManager,
|
||||
FormatterResolver formatterResolver, ILogger<SocialWeatherEndPoint> logger)
|
||||
public SocialWeatherConnectionHandler(PersistentConnectionLifeTimeManager lifetimeManager,
|
||||
FormatterResolver formatterResolver, ILogger<SocialWeatherConnectionHandler> logger)
|
||||
{
|
||||
_lifetimeManager = lifetimeManager;
|
||||
_formatterResolver = formatterResolver;
|
||||
|
|
@ -15,9 +15,7 @@ namespace SocialWeather
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddRouting();
|
||||
services.AddSockets();
|
||||
services.AddSingleton<SocialWeatherEndPoint>();
|
||||
services.AddConnections();
|
||||
services.AddTransient<PersistentConnectionLifeTimeManager>();
|
||||
services.AddSingleton(typeof(JsonStreamFormatter<>), typeof(JsonStreamFormatter<>));
|
||||
services.AddSingleton<PipeWeatherStreamFormatter>();
|
||||
|
|
@ -32,7 +30,7 @@ namespace SocialWeather
|
|||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
|
||||
app.UseSockets(o => { o.MapEndPoint<SocialWeatherEndPoint>("/weather"); });
|
||||
app.UseConnections(o => o.MapConnectionHandler<SocialWeatherConnectionHandler>("/weather"));
|
||||
app.UseFileServer();
|
||||
|
||||
var formatterResolver = app.ApplicationServices.GetRequiredService<FormatterResolver>();
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ using System.Buffers;
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
||||
namespace SocketsSample.EndPoints
|
||||
namespace SocketsSample.ConnectionHandlers
|
||||
{
|
||||
public class MessagesEndPoint : EndPoint
|
||||
public class MessagesConnectionHandler : ConnectionHandler
|
||||
{
|
||||
private ConnectionList Connections { get; } = new ConnectionList();
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using MsgPack.Serialization;
|
||||
using SocketsSample.EndPoints;
|
||||
using SocketsSample.ConnectionHandlers;
|
||||
using SocketsSample.Hubs;
|
||||
using StackExchange.Redis;
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ namespace SocketsSample
|
|||
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSockets();
|
||||
services.AddConnections();
|
||||
|
||||
services.AddSignalR(options =>
|
||||
{
|
||||
|
|
@ -42,8 +42,6 @@ namespace SocketsSample
|
|||
.AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
services.AddSingleton<MessagesEndPoint>();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
|
|
@ -66,9 +64,9 @@ namespace SocketsSample
|
|||
routes.MapHub<HubTChat>("/hubT");
|
||||
});
|
||||
|
||||
app.UseSockets(routes =>
|
||||
app.UseConnections(routes =>
|
||||
{
|
||||
routes.MapEndPoint<MessagesEndPoint>("/chat");
|
||||
routes.MapConnectionHandler<MessagesConnectionHandler>("/chat");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ using System.IO;
|
|||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
||||
{
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ using System.Security.Claims;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.SignalR.Core;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
|
|
@ -313,7 +313,7 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
Abort();
|
||||
}
|
||||
|
||||
// Used by the HubEndPoint only
|
||||
// Used by the HubConnectionHandler only
|
||||
internal Task AbortAsync()
|
||||
{
|
||||
Abort();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Core;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
|
|
@ -15,31 +15,31 @@ using Microsoft.Extensions.Options;
|
|||
|
||||
namespace Microsoft.AspNetCore.SignalR
|
||||
{
|
||||
public class HubEndPoint<THub> : EndPoint where THub : Hub
|
||||
public class HubConnectionHandler<THub> : ConnectionHandler where THub : Hub
|
||||
{
|
||||
private readonly HubLifetimeManager<THub> _lifetimeManager;
|
||||
private readonly ILoggerFactory _loggerFactory;
|
||||
private readonly ILogger<HubEndPoint<THub>> _logger;
|
||||
private readonly ILogger<HubConnectionHandler<THub>> _logger;
|
||||
private readonly IHubProtocolResolver _protocolResolver;
|
||||
private readonly HubOptions<THub> _hubOptions;
|
||||
private readonly HubOptions _globalHubOptions;
|
||||
private readonly IUserIdProvider _userIdProvider;
|
||||
private readonly HubDispatcher<THub> _dispatcher;
|
||||
|
||||
public HubEndPoint(HubLifetimeManager<THub> lifetimeManager,
|
||||
IHubProtocolResolver protocolResolver,
|
||||
IOptions<HubOptions> globalHubOptions,
|
||||
IOptions<HubOptions<THub>> hubOptions,
|
||||
ILoggerFactory loggerFactory,
|
||||
IUserIdProvider userIdProvider,
|
||||
HubDispatcher<THub> dispatcher)
|
||||
public HubConnectionHandler(HubLifetimeManager<THub> lifetimeManager,
|
||||
IHubProtocolResolver protocolResolver,
|
||||
IOptions<HubOptions> globalHubOptions,
|
||||
IOptions<HubOptions<THub>> hubOptions,
|
||||
ILoggerFactory loggerFactory,
|
||||
IUserIdProvider userIdProvider,
|
||||
HubDispatcher<THub> dispatcher)
|
||||
{
|
||||
_protocolResolver = protocolResolver;
|
||||
_lifetimeManager = lifetimeManager;
|
||||
_loggerFactory = loggerFactory;
|
||||
_hubOptions = hubOptions.Value;
|
||||
_globalHubOptions = globalHubOptions.Value;
|
||||
_logger = loggerFactory.CreateLogger<HubEndPoint<THub>>();
|
||||
_logger = loggerFactory.CreateLogger<HubConnectionHandler<THub>>();
|
||||
_userIdProvider = userIdProvider;
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
services.AddSingleton(typeof(IHubProtocolResolver), typeof(DefaultHubProtocolResolver));
|
||||
services.AddSingleton(typeof(IHubContext<>), typeof(HubContext<>));
|
||||
services.AddSingleton(typeof(IHubContext<,>), typeof(HubContext<,>));
|
||||
services.AddSingleton(typeof(HubEndPoint<>), typeof(HubEndPoint<>));
|
||||
services.AddSingleton(typeof(HubConnectionHandler<>), typeof(HubConnectionHandler<>));
|
||||
services.AddSingleton(typeof(IUserIdProvider), typeof(DefaultUserIdProvider));
|
||||
services.AddSingleton(typeof(HubDispatcher<>), typeof(DefaultHubDispatcher<>));
|
||||
services.AddScoped(typeof(IHubActivator<>), typeof(DefaultHubActivator<>));
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// 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 Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
@ -9,10 +9,9 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
public static class SignalRSocketBuilderExtensions
|
||||
{
|
||||
public static IConnectionBuilder UseHub<THub>(this IConnectionBuilder socketBuilder) where THub : Hub
|
||||
public static IConnectionBuilder UseHub<THub>(this IConnectionBuilder connectionBuilder) where THub : Hub
|
||||
{
|
||||
var endpoint = socketBuilder.ApplicationServices.GetRequiredService<HubEndPoint<THub>>();
|
||||
return socketBuilder.Run(connection => endpoint.OnConnectedAsync(connection));
|
||||
return connectionBuilder.UseConnectionHandler<HubConnectionHandler<THub>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Diagnostics;
|
|||
using System.IO;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
||||
using Microsoft.Extensions.Options;
|
||||
using MsgPack;
|
||||
|
|
|
|||
|
|
@ -11,35 +11,35 @@ namespace Microsoft.AspNetCore.SignalR
|
|||
{
|
||||
public class HubRouteBuilder
|
||||
{
|
||||
private readonly SocketRouteBuilder _routes;
|
||||
private readonly ConnectionsRouteBuilder _routes;
|
||||
|
||||
public HubRouteBuilder(SocketRouteBuilder routes)
|
||||
public HubRouteBuilder(ConnectionsRouteBuilder routes)
|
||||
{
|
||||
_routes = routes;
|
||||
}
|
||||
|
||||
public void MapHub<THub>(string path) where THub : Hub
|
||||
{
|
||||
MapHub<THub>(new PathString(path), socketOptions: null);
|
||||
MapHub<THub>(new PathString(path), configureOptions: null);
|
||||
}
|
||||
|
||||
public void MapHub<THub>(PathString path) where THub : Hub
|
||||
{
|
||||
MapHub<THub>(path, socketOptions: null);
|
||||
MapHub<THub>(path, configureOptions: null);
|
||||
}
|
||||
|
||||
public void MapHub<THub>(PathString path, Action<HttpSocketOptions> socketOptions) where THub : Hub
|
||||
public void MapHub<THub>(PathString path, Action<HttpConnectionOptions> configureOptions) where THub : Hub
|
||||
{
|
||||
// find auth attributes
|
||||
var authorizeAttributes = typeof(THub).GetCustomAttributes<AuthorizeAttribute>(inherit: true);
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
foreach (var attribute in authorizeAttributes)
|
||||
{
|
||||
options.AuthorizationData.Add(attribute);
|
||||
}
|
||||
socketOptions?.Invoke(options);
|
||||
configureOptions?.Invoke(options);
|
||||
|
||||
_routes.MapSocket(path, options, builder =>
|
||||
_routes.MapConnections(path, options, builder =>
|
||||
{
|
||||
builder.UseHub<THub>();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Builder
|
|||
"calling 'IServiceCollection.AddSignalR()'.");
|
||||
}
|
||||
|
||||
app.UseSockets(routes =>
|
||||
app.UseConnections(routes =>
|
||||
{
|
||||
configure(new HubRouteBuilder(routes));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
public static ISignalRBuilder AddSignalR(this IServiceCollection services)
|
||||
{
|
||||
services.AddSockets();
|
||||
services.AddConnections();
|
||||
services.AddSingleton<SignalRMarkerService>();
|
||||
services.AddSingleton<IConfigureOptions<HubOptions>, HubOptionsSetup>();
|
||||
return services.AddSignalRCore()
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
// 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;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
public static class ConnectionBuilderExtensions
|
||||
{
|
||||
public static IConnectionBuilder UseEndPoint<TEndPoint>(this IConnectionBuilder connectionBuilder) where TEndPoint : EndPoint
|
||||
{
|
||||
var endpoint = (TEndPoint)connectionBuilder.ApplicationServices.GetService(typeof(TEndPoint));
|
||||
|
||||
if (endpoint == null)
|
||||
{
|
||||
throw new InvalidOperationException($"{nameof(EndPoint)} type {typeof(TEndPoint)} is not registered.");
|
||||
}
|
||||
// This is a terminal middleware, so there's no need to use the 'next' parameter
|
||||
return connectionBuilder.Run(connection => endpoint.OnConnectedAsync(connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,8 +8,8 @@ using System.Security.Claims;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
// 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.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents an end point that multiple connections connect to. For HTTP, endpoints are URLs, for non HTTP it can be a TCP listener (or similar)
|
||||
/// </summary>
|
||||
public abstract class EndPoint
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when a new connection is accepted to the endpoint
|
||||
/// </summary>
|
||||
/// <param name="connection">The new <see cref="ConnectionContext"/></param>
|
||||
/// <returns>A <see cref="Task"/> that represents the connection lifetime. When the task completes, the connection is complete.</returns>
|
||||
public abstract Task OnConnectedAsync(ConnectionContext connection);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.AspNetCore.Protocols.Features
|
||||
namespace Microsoft.AspNetCore.Connections.Features
|
||||
{
|
||||
public class ConnectionInherentKeepAliveFeature : IConnectionInherentKeepAliveFeature
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Protocols.Abstractions" Version="$(MicrosoftAspNetCoreProtocolsAbstractionsPackageVersion)" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="$(MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Internal;
|
||||
using Microsoft.AspNetCore.Sockets.Http.Internal;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO.Pipelines;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ using System.Net.Http;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,9 +21,6 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsPackageVersion)" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
|
||||
<PackageReference Include="System.IO.Pipelines" Version="$(SystemIOPipelinesPackageVersion)" />
|
||||
<PackageReference Include="System.Memory" Version="$(SystemMemoryPackageVersion)" />
|
||||
<PackageReference Include="System.Numerics.Vectors" Version="$(SystemNumericsVectorsPackageVersion)" />
|
||||
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ using System.Net.Http;
|
|||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
using Microsoft.AspNetCore.Sockets.Internal.Formatters;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Client
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using System.Net.WebSockets;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
|
|
|||
|
|
@ -8,15 +8,15 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
public static class SocketsAppBuilderExtensions
|
||||
public static class ConnectionsAppBuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseSockets(this IApplicationBuilder app, Action<SocketRouteBuilder> callback)
|
||||
public static IApplicationBuilder UseConnections(this IApplicationBuilder app, Action<ConnectionsRouteBuilder> callback)
|
||||
{
|
||||
var dispatcher = app.ApplicationServices.GetRequiredService<HttpConnectionDispatcher>();
|
||||
|
||||
var routes = new RouteBuilder(app);
|
||||
|
||||
callback(new SocketRouteBuilder(routes, dispatcher));
|
||||
callback(new ConnectionsRouteBuilder(routes, dispatcher));
|
||||
|
||||
app.UseWebSockets();
|
||||
app.UseRouter(routes.Build());
|
||||
|
|
@ -6,9 +6,9 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class SocketsDependencyInjectionExtensions
|
||||
public static class ConnectionsDependencyInjectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddSockets(this IServiceCollection services)
|
||||
public static IServiceCollection AddConnections(this IServiceCollection services)
|
||||
{
|
||||
services.AddRouting();
|
||||
services.AddAuthorizationPolicyEvaluator();
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// 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;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
public class ConnectionsRouteBuilder
|
||||
{
|
||||
private readonly HttpConnectionDispatcher _dispatcher;
|
||||
private readonly RouteBuilder _routes;
|
||||
|
||||
public ConnectionsRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher)
|
||||
{
|
||||
_routes = routes;
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public void MapConnections(string path, Action<IConnectionBuilder> configure) =>
|
||||
MapConnections(new PathString(path), new HttpConnectionOptions(), configure);
|
||||
|
||||
public void MapConnections(PathString path, Action<IConnectionBuilder> configure) =>
|
||||
MapConnections(path, new HttpConnectionOptions(), configure);
|
||||
|
||||
public void MapConnections(PathString path, HttpConnectionOptions options, Action<IConnectionBuilder> configure)
|
||||
{
|
||||
var connectionBuilder = new ConnectionBuilder(_routes.ServiceProvider);
|
||||
configure(connectionBuilder);
|
||||
var socket = connectionBuilder.Build();
|
||||
_routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket));
|
||||
_routes.MapRoute(path + "/negotiate", c => _dispatcher.ExecuteNegotiateAsync(c, options));
|
||||
}
|
||||
|
||||
public void MapConnectionHandler<TConnectionHandler>(string path) where TConnectionHandler : ConnectionHandler
|
||||
{
|
||||
MapConnectionHandler<TConnectionHandler>(new PathString(path), configureOptions: null);
|
||||
}
|
||||
|
||||
public void MapConnectionHandler<TConnectionHandler>(PathString path) where TConnectionHandler : ConnectionHandler
|
||||
{
|
||||
MapConnectionHandler<TConnectionHandler>(path, configureOptions: null);
|
||||
}
|
||||
|
||||
public void MapConnectionHandler<TConnectionHandler>(PathString path, Action<HttpConnectionOptions> configureOptions) where TConnectionHandler : ConnectionHandler
|
||||
{
|
||||
var authorizeAttributes = typeof(TConnectionHandler).GetCustomAttributes<AuthorizeAttribute>(inherit: true);
|
||||
var options = new HttpConnectionOptions();
|
||||
foreach (var attribute in authorizeAttributes)
|
||||
{
|
||||
options.AuthorizationData.Add(attribute);
|
||||
}
|
||||
configureOptions?.Invoke(options);
|
||||
|
||||
MapConnections(path, options, builder =>
|
||||
{
|
||||
builder.UseConnectionHandler<TConnectionHandler>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets.Http.Features;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
LoggerMessage.Define<long>(LogLevel.Trace, new EventId(6, "ReceivedBytes"), "Received {Count} bytes.");
|
||||
|
||||
private static readonly Action<ILogger, TransportType, Exception> _transportNotSupported =
|
||||
LoggerMessage.Define<TransportType>(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this endpoint type.");
|
||||
LoggerMessage.Define<TransportType>(LogLevel.Debug, new EventId(7, "TransportNotSupported"), "{TransportType} transport not supported by this connection handler.");
|
||||
|
||||
private static readonly Action<ILogger, TransportType, TransportType, Exception> _cannotChangeTransport =
|
||||
LoggerMessage.Define<TransportType, TransportType>(LogLevel.Error, new EventId(8, "CannotChangeTransport"), "Cannot change transports mid-connection; currently using {TransportType}, requesting {RequestedTransport}.");
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ using System.Threading.Tasks;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.AspNetCore.Sockets.Internal;
|
||||
using Microsoft.AspNetCore.Sockets.Internal.Transports;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
_logger = _loggerFactory.CreateLogger<HttpConnectionDispatcher>();
|
||||
}
|
||||
|
||||
public async Task ExecuteAsync(HttpContext context, HttpSocketOptions options, ConnectionDelegate connectionDelegate)
|
||||
public async Task ExecuteAsync(HttpContext context, HttpConnectionOptions options, ConnectionDelegate connectionDelegate)
|
||||
{
|
||||
// Create the log scope and attempt to pass the Connection ID to it so as many logs as possible contain
|
||||
// the Connection ID metadata. If this is the negotiate request then the Connection ID for the scope will
|
||||
|
|
@ -56,7 +56,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
else if (HttpMethods.IsGet(context.Request.Method))
|
||||
{
|
||||
// GET /{path}
|
||||
await ExecuteEndpointAsync(context, connectionDelegate, options, logScope);
|
||||
await ExecuteAsync(context, connectionDelegate, options, logScope);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
}
|
||||
}
|
||||
|
||||
public async Task ExecuteNegotiateAsync(HttpContext context, HttpSocketOptions options)
|
||||
public async Task ExecuteNegotiateAsync(HttpContext context, HttpConnectionOptions options)
|
||||
{
|
||||
// Create the log scope and the scope connectionId param will be set when the connection is created.
|
||||
var logScope = new ConnectionLogScope(connectionId: string.Empty);
|
||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
}
|
||||
}
|
||||
|
||||
private async Task ExecuteEndpointAsync(HttpContext context, ConnectionDelegate connectionDelegate, HttpSocketOptions options, ConnectionLogScope logScope)
|
||||
private async Task ExecuteAsync(HttpContext context, ConnectionDelegate connectionDelegate, HttpConnectionOptions options, ConnectionLogScope logScope)
|
||||
{
|
||||
var supportedTransports = options.Transports;
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
await connectionDelegate(connection);
|
||||
}
|
||||
|
||||
private Task ProcessNegotiate(HttpContext context, HttpSocketOptions options, ConnectionLogScope logScope)
|
||||
private Task ProcessNegotiate(HttpContext context, HttpConnectionOptions options, ConnectionLogScope logScope)
|
||||
{
|
||||
context.Response.ContentType = "application/json";
|
||||
|
||||
|
|
@ -377,7 +377,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
return context.Response.Body.WriteAsync(negotiateResponseBuffer, 0, negotiateResponseBuffer.Length);
|
||||
}
|
||||
|
||||
private static string GetNegotiatePayload(string connectionId, HttpContext context, HttpSocketOptions options)
|
||||
private static string GetNegotiatePayload(string connectionId, HttpContext context, HttpConnectionOptions options)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
using (var jsonWriter = new JsonTextWriter(new StringWriter(sb)))
|
||||
|
|
@ -441,7 +441,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
|
||||
private static string GetConnectionId(HttpContext context) => context.Request.Query["id"];
|
||||
|
||||
private async Task ProcessSend(HttpContext context, HttpSocketOptions options)
|
||||
private async Task ProcessSend(HttpContext context, HttpConnectionOptions options)
|
||||
{
|
||||
var connection = await GetConnectionAsync(context, options);
|
||||
if (connection == null)
|
||||
|
|
@ -471,7 +471,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
await connection.Application.Output.FlushAsync();
|
||||
}
|
||||
|
||||
private async Task<bool> EnsureConnectionStateAsync(DefaultConnectionContext connection, HttpContext context, TransportType transportType, TransportType supportedTransports, ConnectionLogScope logScope, HttpSocketOptions options)
|
||||
private async Task<bool> EnsureConnectionStateAsync(DefaultConnectionContext connection, HttpContext context, TransportType transportType, TransportType supportedTransports, ConnectionLogScope logScope, HttpConnectionOptions options)
|
||||
{
|
||||
if ((supportedTransports & transportType) == 0)
|
||||
{
|
||||
|
|
@ -596,7 +596,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
return newHttpContext;
|
||||
}
|
||||
|
||||
private async Task<DefaultConnectionContext> GetConnectionAsync(HttpContext context, HttpSocketOptions options)
|
||||
private async Task<DefaultConnectionContext> GetConnectionAsync(HttpContext context, HttpConnectionOptions options)
|
||||
{
|
||||
var connectionId = GetConnectionId(context);
|
||||
|
||||
|
|
@ -623,7 +623,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
return connection;
|
||||
}
|
||||
|
||||
private void EnsureConnectionStateInternal(DefaultConnectionContext connection, HttpSocketOptions options)
|
||||
private void EnsureConnectionStateInternal(DefaultConnectionContext connection, HttpConnectionOptions options)
|
||||
{
|
||||
// If the connection doesn't have a pipe yet then create one, we lazily create the pipe to save on allocations until the client actually connects
|
||||
if (connection.Transport == null)
|
||||
|
|
@ -637,7 +637,7 @@ namespace Microsoft.AspNetCore.Sockets
|
|||
}
|
||||
|
||||
// This is only used for WebSockets connections, which can connect directly without negotiating
|
||||
private async Task<DefaultConnectionContext> GetOrCreateConnectionAsync(HttpContext context, HttpSocketOptions options)
|
||||
private async Task<DefaultConnectionContext> GetOrCreateConnectionAsync(HttpContext context, HttpConnectionOptions options)
|
||||
{
|
||||
var connectionId = GetConnectionId(context);
|
||||
DefaultConnectionContext connection;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
public class HttpSocketOptions
|
||||
public class HttpConnectionOptions
|
||||
{
|
||||
public IList<IAuthorizeData> AuthorizationData { get; } = new List<IAuthorizeData>();
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets.Internal.Transports
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
// 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;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Microsoft.AspNetCore.Sockets
|
||||
{
|
||||
public class SocketRouteBuilder
|
||||
{
|
||||
private readonly HttpConnectionDispatcher _dispatcher;
|
||||
private readonly RouteBuilder _routes;
|
||||
|
||||
public SocketRouteBuilder(RouteBuilder routes, HttpConnectionDispatcher dispatcher)
|
||||
{
|
||||
_routes = routes;
|
||||
_dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
public void MapSocket(string path, Action<IConnectionBuilder> socketConfig) =>
|
||||
MapSocket(new PathString(path), new HttpSocketOptions(), socketConfig);
|
||||
|
||||
public void MapSocket(PathString path, Action<IConnectionBuilder> socketConfig) =>
|
||||
MapSocket(path, new HttpSocketOptions(), socketConfig);
|
||||
|
||||
public void MapSocket(PathString path, HttpSocketOptions options, Action<IConnectionBuilder> connectionConfig)
|
||||
{
|
||||
var connectionBuilder = new ConnectionBuilder(_routes.ServiceProvider);
|
||||
connectionConfig(connectionBuilder);
|
||||
var socket = connectionBuilder.Build();
|
||||
_routes.MapRoute(path, c => _dispatcher.ExecuteAsync(c, options, socket));
|
||||
_routes.MapRoute(path + "/negotiate", c => _dispatcher.ExecuteNegotiateAsync(c, options));
|
||||
}
|
||||
|
||||
public void MapEndPoint<TEndPoint>(string path) where TEndPoint : EndPoint
|
||||
{
|
||||
MapEndPoint<TEndPoint>(new PathString(path), socketOptions: null);
|
||||
}
|
||||
|
||||
public void MapEndPoint<TEndPoint>(PathString path) where TEndPoint : EndPoint
|
||||
{
|
||||
MapEndPoint<TEndPoint>(path, socketOptions: null);
|
||||
}
|
||||
|
||||
public void MapEndPoint<TEndPoint>(PathString path, Action<HttpSocketOptions> socketOptions) where TEndPoint : EndPoint
|
||||
{
|
||||
var authorizeAttributes = typeof(TEndPoint).GetCustomAttributes<AuthorizeAttribute>(inherit: true);
|
||||
var options = new HttpSocketOptions();
|
||||
foreach (var attribute in authorizeAttributes)
|
||||
{
|
||||
options.AuthorizationData.Add(attribute);
|
||||
}
|
||||
socketOptions?.Invoke(options);
|
||||
|
||||
MapSocket(path, options, builder =>
|
||||
{
|
||||
builder.UseEndPoint<TEndPoint>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Net;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Client.Tests;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Client.Tests;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Moq;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Net;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Client.Tests;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Net;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Client.Tests;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Xunit;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using System.Security.Cryptography.X509Certificates;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Client.Tests;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Client.Tests;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Newtonsoft.Json;
|
||||
using SocketsTransportType = Microsoft.AspNetCore.Sockets.TransportType;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using System.Threading;
|
|||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Client.Tests;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using System.Threading;
|
|||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.IO.Pipelines;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
|
||||
public async Task<Task> ConnectAsync(
|
||||
EndPoint endPoint,
|
||||
Connections.ConnectionHandler handler,
|
||||
bool sendHandshakeRequestMessage = true,
|
||||
bool expectedHandshakeResponseMessage = true)
|
||||
{
|
||||
|
|
@ -64,7 +64,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
}
|
||||
|
||||
var connection = endPoint.OnConnectedAsync(Connection);
|
||||
var connection = handler.OnConnectedAsync(Connection);
|
||||
|
||||
if (expectedHandshakeResponseMessage)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
using System.Buffers;
|
||||
using System.IO.Pipelines;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class EchoEndPoint : EndPoint
|
||||
public class EchoConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override async Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -9,7 +9,7 @@ using System.Net.WebSockets;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
|
|
@ -215,7 +215,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
catch (OperationCanceledException)
|
||||
{
|
||||
// Because the server and client are run in the same process there is a race where websocket.SendAsync
|
||||
// can send a message but before returning be suspended allowing the server to run the EchoEndpoint and
|
||||
// can send a message but before returning be suspended allowing the server to run the EchoConnectionHandler and
|
||||
// send a close frame which triggers a cancellation token on the client and cancels the websocket.SendAsync.
|
||||
// Our solution to this is to just catch OperationCanceledException from the sent message if the race happens
|
||||
// because we know the send went through, and its safe to check the response.
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Http.Features;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class HttpHeaderEndPoint : EndPoint
|
||||
public class HttpHeaderConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override async Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -9,7 +9,7 @@ using System.Threading.Channels;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class MethodHub : TestHub
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ using Microsoft.AspNetCore.Sockets;
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils
|
||||
namespace Microsoft.AspNetCore.SignalR.Tests
|
||||
{
|
||||
public class HubEndPointTestUtils
|
||||
public class HubConnectionHandlerTestUtils
|
||||
{
|
||||
public static Type GetEndPointType(Type hubType)
|
||||
public static Type GetConnectionHandlerType(Type hubType)
|
||||
{
|
||||
var endPointType = typeof(HubEndPoint<>);
|
||||
return endPointType.MakeGenericType(hubType);
|
||||
var connectionHandlerType = typeof(HubConnectionHandler<>);
|
||||
return connectionHandlerType.MakeGenericType(hubType);
|
||||
}
|
||||
|
||||
public static Type GetGenericType(Type genericType, Type hubType)
|
||||
|
|
@ -65,10 +65,10 @@ namespace Microsoft.AspNetCore.SignalR.Tests.HubEndpointTestUtils
|
|||
return services.BuildServiceProvider();
|
||||
}
|
||||
|
||||
public static EndPoint GetHubEndpoint(Type hubType)
|
||||
public static Connections.ConnectionHandler GetHubConnectionHandler(Type hubType)
|
||||
{
|
||||
var serviceProvider = CreateServiceProvider();
|
||||
return (EndPoint)serviceProvider.GetService(GetEndPointType(hubType));
|
||||
return (Connections.ConnectionHandler)serviceProvider.GetService(GetConnectionHandlerType(hubType));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.SignalR.Internal;
|
||||
using Microsoft.AspNetCore.SignalR.Internal.Protocol;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
var ex = Assert.Throws<NotSupportedException>(() =>
|
||||
{
|
||||
using (var builder = BuildWebHost(options => options.MapHub<InvalidHub>("/overloads")))
|
||||
using (var builder = BuildWebHost(routes => routes.MapHub<InvalidHub>("/overloads")))
|
||||
{
|
||||
builder.Start();
|
||||
}
|
||||
|
|
@ -31,9 +31,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
.Configure(app =>
|
||||
{
|
||||
var ex = Assert.Throws<InvalidOperationException>(() => {
|
||||
app.UseSignalR(options =>
|
||||
app.UseSignalR(routes =>
|
||||
{
|
||||
options.MapHub<AuthHub>("/overloads");
|
||||
routes.MapHub<AuthHub>("/overloads");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -47,9 +47,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
public void MapHubFindsAuthAttributeOnHub()
|
||||
{
|
||||
var authCount = 0;
|
||||
using (var builder = BuildWebHost(options => options.MapHub<AuthHub>("/path", httpSocketOptions =>
|
||||
using (var builder = BuildWebHost(routes => routes.MapHub<AuthHub>("/path", options =>
|
||||
{
|
||||
authCount += httpSocketOptions.AuthorizationData.Count;
|
||||
authCount += options.AuthorizationData.Count;
|
||||
})))
|
||||
{
|
||||
builder.Start();
|
||||
|
|
@ -62,9 +62,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
public void MapHubFindsAuthAttributeOnInheritedHub()
|
||||
{
|
||||
var authCount = 0;
|
||||
using (var builder = BuildWebHost(options => options.MapHub<InheritedAuthHub>("/path", httpSocketOptions =>
|
||||
using (var builder = BuildWebHost(routes => routes.MapHub<InheritedAuthHub>("/path", options =>
|
||||
{
|
||||
authCount += httpSocketOptions.AuthorizationData.Count;
|
||||
authCount += options.AuthorizationData.Count;
|
||||
})))
|
||||
{
|
||||
builder.Start();
|
||||
|
|
@ -77,9 +77,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
public void MapHubFindsMultipleAuthAttributesOnDoubleAuthHub()
|
||||
{
|
||||
var authCount = 0;
|
||||
using (var builder = BuildWebHost(options => options.MapHub<DoubleAuthHub>("/path", httpSocketOptions =>
|
||||
using (var builder = BuildWebHost(routes => routes.MapHub<DoubleAuthHub>("/path", options =>
|
||||
{
|
||||
authCount += httpSocketOptions.AuthorizationData.Count;
|
||||
authCount += options.AuthorizationData.Count;
|
||||
})))
|
||||
{
|
||||
builder.Start();
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSockets();
|
||||
services.AddConnections();
|
||||
services.AddSignalR();
|
||||
services.AddSingleton<EchoEndPoint>();
|
||||
services.AddSingleton<HttpHeaderEndPoint>();
|
||||
services.AddSingleton<EchoConnectionHandler>();
|
||||
services.AddSingleton<HttpHeaderConnectionHandler>();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
app.UseSockets(options => options.MapEndPoint<EchoEndPoint>("/echo"));
|
||||
app.UseSockets(options => options.MapEndPoint<HttpHeaderEndPoint>("/httpheader"));
|
||||
app.UseConnections(options => options.MapConnectionHandler<EchoConnectionHandler>("/echo"));
|
||||
app.UseConnections(options => options.MapConnectionHandler<HttpHeaderConnectionHandler>("/httpheader"));
|
||||
app.UseSignalR(options => options.MapHub<UncreatableHub>("/uncreatable"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ using System.Reflection;
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets;
|
||||
using Microsoft.AspNetCore.Sockets.Client;
|
||||
using Microsoft.AspNetCore.Sockets.Client.Http;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Http.Internal;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Protocols.Features;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Connections.Features;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
|
|
@ -46,13 +46,13 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
|
||||
var context = new DefaultHttpContext();
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
var ms = new MemoryStream();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
context.Response.Body = ms;
|
||||
await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions());
|
||||
await dispatcher.ExecuteNegotiateAsync(context, new HttpConnectionOptions());
|
||||
var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
|
||||
var connectionId = negotiateResponse.Value<string>("connectionId");
|
||||
Assert.True(manager.TryGetConnection(connectionId, out var connectionContext));
|
||||
|
|
@ -69,20 +69,20 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
|
||||
var context = new DefaultHttpContext();
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
var ms = new MemoryStream();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
context.Response.Body = ms;
|
||||
var httpSocketOptions = new HttpSocketOptions { TransportMaxBufferSize = 4, ApplicationMaxBufferSize = 4 };
|
||||
await dispatcher.ExecuteNegotiateAsync(context, httpSocketOptions);
|
||||
var options = new HttpConnectionOptions { TransportMaxBufferSize = 4, ApplicationMaxBufferSize = 4 };
|
||||
await dispatcher.ExecuteNegotiateAsync(context, options);
|
||||
var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
|
||||
var connectionId = negotiateResponse.Value<string>("connectionId");
|
||||
context.Request.QueryString = context.Request.QueryString.Add("id", connectionId);
|
||||
Assert.True(manager.TryGetConnection(connectionId, out var connection));
|
||||
// Fake actual connection after negotiate to populate the pipes on the connection
|
||||
await dispatcher.ExecuteAsync(context, httpSocketOptions, c => Task.CompletedTask);
|
||||
await dispatcher.ExecuteAsync(context, options, c => Task.CompletedTask);
|
||||
|
||||
// This write should complete immediately but it exceeds the writer threshold
|
||||
var writeTask = connection.Application.Output.WriteAsync(new byte[] { (byte)'b', (byte)'y', (byte)'t', (byte)'e', (byte)'s' });
|
||||
|
|
@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = responseBody;
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
|
|
@ -131,11 +131,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
|
||||
// This task should complete immediately but it exceeds the writer threshold
|
||||
var executeTask = dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
var executeTask = dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
Assert.False(executeTask.IsCompleted);
|
||||
await connection.Transport.Input.ConsumeAsync(10);
|
||||
await executeTask.OrTimeout();
|
||||
|
|
@ -161,13 +161,13 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
|
||||
context.Features.Set<IHttpWebSocketFeature>(new TestWebSocketConnectionFeature());
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
var ms = new MemoryStream();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
context.Response.Body = ms;
|
||||
await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions { Transports = transports });
|
||||
await dispatcher.ExecuteNegotiateAsync(context, new HttpConnectionOptions { Transports = transports });
|
||||
|
||||
var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
|
||||
var availableTransports = (TransportType)0;
|
||||
|
|
@ -199,7 +199,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = strm;
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "GET";
|
||||
|
|
@ -210,9 +210,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, transportType);
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status404NotFound, context.Response.StatusCode);
|
||||
await strm.FlushAsync();
|
||||
|
|
@ -235,7 +235,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = strm;
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
|
|
@ -245,9 +245,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status404NotFound, context.Response.StatusCode);
|
||||
await strm.FlushAsync();
|
||||
|
|
@ -272,7 +272,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = strm;
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
|
|
@ -282,9 +282,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status405MethodNotAllowed, context.Response.StatusCode);
|
||||
await strm.FlushAsync();
|
||||
|
|
@ -317,7 +317,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = responseBody;
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
|
|
@ -327,10 +327,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.True(connection.Transport.Input.TryRead(out var result));
|
||||
Assert.Equal("Hello World", Encoding.UTF8.GetString(result.Buffer.ToArray()));
|
||||
|
|
@ -356,7 +356,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = responseBody;
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<HttpContextEndPoint>();
|
||||
services.AddSingleton<HttpContextConnectionHandler>();
|
||||
services.AddOptions();
|
||||
|
||||
// Setup state on the HttpContext
|
||||
|
|
@ -379,11 +379,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Connection.RemotePort = 43456;
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<HttpContextEndPoint>();
|
||||
builder.UseConnectionHandler<HttpContextConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
|
||||
// Start a poll
|
||||
var task = dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
var task = dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
// Send to the application
|
||||
var buffer = Encoding.UTF8.GetBytes("Hello World");
|
||||
|
|
@ -445,16 +445,16 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = strm;
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "GET";
|
||||
|
||||
SetTransport(context, transportType);
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
|
||||
await strm.FlushAsync();
|
||||
|
|
@ -476,14 +476,14 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = strm;
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status400BadRequest, context.Response.StatusCode);
|
||||
await strm.FlushAsync();
|
||||
|
|
@ -552,11 +552,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, TransportType.ServerSentEvents);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<ImmediatelyCompleteEndPoint>();
|
||||
services.AddSingleton<ImmediatelyCompleteConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
|
||||
builder.UseConnectionHandler<ImmediatelyCompleteConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
|
||||
|
||||
|
|
@ -578,11 +578,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, TransportType.ServerSentEvents);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<SynchronusExceptionEndPoint>();
|
||||
services.AddSingleton<SynchronusExceptionConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<SynchronusExceptionEndPoint>();
|
||||
builder.UseConnectionHandler<SynchronusExceptionConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
|
||||
|
||||
|
|
@ -604,11 +604,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = MakeRequest("/foo", connection);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<ImmediatelyCompleteEndPoint>();
|
||||
services.AddSingleton<ImmediatelyCompleteConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
|
||||
builder.UseConnectionHandler<ImmediatelyCompleteConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
await dispatcher.ExecuteAsync(context, new HttpSocketOptions(), app);
|
||||
await dispatcher.ExecuteAsync(context, new HttpConnectionOptions(), app);
|
||||
|
||||
Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode);
|
||||
|
||||
|
|
@ -630,11 +630,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = MakeRequest("/foo", connection);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.LongPolling.PollTimeout = TimeSpan.FromSeconds(2);
|
||||
await dispatcher.ExecuteAsync(context, options, app).OrTimeout();
|
||||
|
||||
|
|
@ -656,11 +656,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, TransportType.WebSockets);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<ImmediatelyCompleteEndPoint>();
|
||||
services.AddSingleton<ImmediatelyCompleteConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
|
||||
builder.UseConnectionHandler<ImmediatelyCompleteConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.WebSockets.CloseTimeout = TimeSpan.FromSeconds(1);
|
||||
|
||||
var task = dispatcher.ExecuteAsync(context, options, app);
|
||||
|
|
@ -688,11 +688,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context2, transportType);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
var request1 = dispatcher.ExecuteAsync(context1, options, app);
|
||||
|
||||
await dispatcher.ExecuteAsync(context2, options, app);
|
||||
|
|
@ -727,11 +727,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context2 = MakeRequest("/foo", connection);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
var request1 = dispatcher.ExecuteAsync(context1, options, app);
|
||||
var request2 = dispatcher.ExecuteAsync(context2, options, app);
|
||||
|
||||
|
|
@ -765,11 +765,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, transportType);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
await dispatcher.ExecuteAsync(context, options, app);
|
||||
|
||||
|
||||
|
|
@ -790,11 +790,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = MakeRequest("/foo", connection);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
var task = dispatcher.ExecuteAsync(context, options, app);
|
||||
|
||||
var buffer = Encoding.UTF8.GetBytes("Hello World");
|
||||
|
|
@ -825,11 +825,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, TransportType.ServerSentEvents);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<BlockingEndPoint>();
|
||||
services.AddSingleton<BlockingConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<BlockingEndPoint>();
|
||||
builder.UseConnectionHandler<BlockingConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
var task = dispatcher.ExecuteAsync(context, options, app);
|
||||
|
||||
var buffer = Encoding.UTF8.GetBytes("Hello World");
|
||||
|
|
@ -858,11 +858,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = MakeRequest("/foo", connection);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<BlockingEndPoint>();
|
||||
services.AddSingleton<BlockingConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<BlockingEndPoint>();
|
||||
builder.UseConnectionHandler<BlockingConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
var task = dispatcher.ExecuteAsync(context, options, app);
|
||||
|
||||
var buffer = Encoding.UTF8.GetBytes("Hello World");
|
||||
|
|
@ -889,11 +889,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var dispatcher = new HttpConnectionDispatcher(manager, loggerFactory);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
|
||||
var context1 = MakeRequest("/foo", connection);
|
||||
var task1 = dispatcher.ExecuteAsync(context1, options, app);
|
||||
|
|
@ -933,12 +933,12 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
SetTransport(context, transportType);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<ImmediatelyCompleteEndPoint>();
|
||||
services.AddSingleton<ImmediatelyCompleteConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
|
||||
builder.UseConnectionHandler<ImmediatelyCompleteConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.WebSockets.CloseTimeout = TimeSpan.FromSeconds(0);
|
||||
await dispatcher.ExecuteAsync(context, options, app);
|
||||
|
||||
|
|
@ -961,7 +961,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = new DefaultHttpContext();
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddAuthorizationPolicyEvaluator();
|
||||
services.AddAuthorization(o =>
|
||||
{
|
||||
|
|
@ -983,9 +983,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(sp);
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("test"));
|
||||
|
||||
// would hang if EndPoint was running
|
||||
|
|
@ -1006,7 +1006,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = new DefaultHttpContext();
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddAuthorizationPolicyEvaluator();
|
||||
services.AddAuthorization(o =>
|
||||
{
|
||||
|
|
@ -1028,9 +1028,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(sp);
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("test"));
|
||||
|
||||
context.User = new ClaimsPrincipal(new ClaimsIdentity("authenticated"));
|
||||
|
|
@ -1054,7 +1054,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddAuthorizationPolicyEvaluator();
|
||||
services.AddAuthorization(o =>
|
||||
{
|
||||
|
|
@ -1080,18 +1080,18 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = new MemoryStream();
|
||||
|
||||
var builder = new ConnectionBuilder(sp);
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("test"));
|
||||
|
||||
// "authorize" user
|
||||
context.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "name") }));
|
||||
|
||||
var endPointTask = dispatcher.ExecuteAsync(context, options, app);
|
||||
var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app);
|
||||
await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World")).AsTask().OrTimeout();
|
||||
|
||||
await endPointTask.OrTimeout();
|
||||
await connectionHandlerTask.OrTimeout();
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
|
||||
Assert.Equal("Hello, World", GetContentAsString(context.Response.Body));
|
||||
|
|
@ -1110,7 +1110,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddAuthorizationPolicyEvaluator();
|
||||
services.AddAuthorization(o =>
|
||||
{
|
||||
|
|
@ -1140,9 +1140,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = new MemoryStream();
|
||||
|
||||
var builder = new ConnectionBuilder(sp);
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("test"));
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("secondPolicy"));
|
||||
|
||||
|
|
@ -1169,10 +1169,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
new Claim(ClaimTypes.StreetAddress, "12345 123rd St. NW")
|
||||
}));
|
||||
|
||||
var endPointTask = dispatcher.ExecuteAsync(context, options, app);
|
||||
var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app);
|
||||
await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World")).AsTask().OrTimeout();
|
||||
|
||||
await endPointTask.OrTimeout();
|
||||
await connectionHandlerTask.OrTimeout();
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
|
||||
Assert.Equal("Hello, World", GetContentAsString(context.Response.Body));
|
||||
|
|
@ -1191,7 +1191,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddAuthorization(o =>
|
||||
{
|
||||
o.AddPolicy("test", policy =>
|
||||
|
|
@ -1218,18 +1218,18 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = new MemoryStream();
|
||||
|
||||
var builder = new ConnectionBuilder(sp);
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("test"));
|
||||
|
||||
// "authorize" user
|
||||
context.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(ClaimTypes.NameIdentifier, "name") }));
|
||||
|
||||
var endPointTask = dispatcher.ExecuteAsync(context, options, app);
|
||||
var connectionHandlerTask = dispatcher.ExecuteAsync(context, options, app);
|
||||
await connection.Transport.Output.WriteAsync(Encoding.UTF8.GetBytes("Hello, World")).AsTask().OrTimeout();
|
||||
|
||||
await endPointTask.OrTimeout();
|
||||
await connectionHandlerTask.OrTimeout();
|
||||
|
||||
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
|
||||
Assert.Equal("Hello, World", GetContentAsString(context.Response.Body));
|
||||
|
|
@ -1247,7 +1247,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = new DefaultHttpContext();
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddAuthorization(o =>
|
||||
{
|
||||
o.AddPolicy("test", policy =>
|
||||
|
|
@ -1274,9 +1274,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = new MemoryStream();
|
||||
|
||||
var builder = new ConnectionBuilder(sp);
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.AuthorizationData.Add(new AuthorizeAttribute("test"));
|
||||
|
||||
// "authorize" user
|
||||
|
|
@ -1302,11 +1302,11 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = MakeRequest("/foo", connection);
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<TestEndPoint>();
|
||||
builder.UseConnectionHandler<TestConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.LongPolling.PollTimeout = TimeSpan.FromMilliseconds(1); // We don't care about the poll itself
|
||||
|
||||
Assert.Null(connection.Features.Get<IConnectionInherentKeepAliveFeature>());
|
||||
|
|
@ -1328,13 +1328,13 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
var context = new DefaultHttpContext();
|
||||
context.Features.Set<IHttpResponseFeature>(new ResponseFeature());
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<TestEndPoint>();
|
||||
services.AddSingleton<TestConnectionHandler>();
|
||||
services.AddOptions();
|
||||
var ms = new MemoryStream();
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "POST";
|
||||
context.Response.Body = ms;
|
||||
await dispatcher.ExecuteNegotiateAsync(context, new HttpSocketOptions { Transports = TransportType.WebSockets });
|
||||
await dispatcher.ExecuteNegotiateAsync(context, new HttpConnectionOptions { Transports = TransportType.WebSockets });
|
||||
|
||||
var negotiateResponse = JsonConvert.DeserializeObject<JObject>(Encoding.UTF8.GetString(ms.ToArray()));
|
||||
var availableTransports = (JArray)negotiateResponse["availableTransports"];
|
||||
|
|
@ -1399,7 +1399,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Response.Body = strm;
|
||||
var services = new ServiceCollection();
|
||||
services.AddOptions();
|
||||
services.AddSingleton<ImmediatelyCompleteEndPoint>();
|
||||
services.AddSingleton<ImmediatelyCompleteConnectionHandler>();
|
||||
SetTransport(context, transportType);
|
||||
context.Request.Path = "/foo";
|
||||
context.Request.Method = "GET";
|
||||
|
|
@ -1409,9 +1409,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
context.Request.Query = qs;
|
||||
|
||||
var builder = new ConnectionBuilder(services.BuildServiceProvider());
|
||||
builder.UseEndPoint<ImmediatelyCompleteEndPoint>();
|
||||
builder.UseConnectionHandler<ImmediatelyCompleteConnectionHandler>();
|
||||
var app = builder.Build();
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
options.Transports = supportedTransports;
|
||||
|
||||
await dispatcher.ExecuteAsync(context, options, app);
|
||||
|
|
@ -1475,7 +1475,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class NerverEndingEndPoint : EndPoint
|
||||
public class NerverEndingConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -1484,7 +1484,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class BlockingEndPoint : EndPoint
|
||||
public class BlockingConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -1494,7 +1494,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class SynchronusExceptionEndPoint : EndPoint
|
||||
public class SynchronusExceptionConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -1502,7 +1502,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class ImmediatelyCompleteEndPoint : EndPoint
|
||||
public class ImmediatelyCompleteConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -1510,7 +1510,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class HttpContextEndPoint : EndPoint
|
||||
public class HttpContextConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override async Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -1543,7 +1543,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
public class TestEndPoint : EndPoint
|
||||
public class TestConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override async Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
[Fact]
|
||||
public void CheckLongPollingTimeoutValue()
|
||||
{
|
||||
var options = new HttpSocketOptions();
|
||||
var options = new HttpConnectionOptions();
|
||||
Assert.Equal(options.LongPolling.PollTimeout, TimeSpan.FromSeconds(90));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -19,20 +19,20 @@ using Xunit.Abstractions;
|
|||
|
||||
namespace Microsoft.AspNetCore.Sockets.Tests
|
||||
{
|
||||
public class MapEndPointTests
|
||||
public class MapConnectionHandlerTests
|
||||
{
|
||||
private ITestOutputHelper _output;
|
||||
|
||||
public MapEndPointTests(ITestOutputHelper output)
|
||||
public MapConnectionHandlerTests(ITestOutputHelper output)
|
||||
{
|
||||
_output = output;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MapEndPointFindsAuthAttributeOnEndPoint()
|
||||
public void MapConnectionHandlerFindsAuthAttributeOnEndPoint()
|
||||
{
|
||||
var authCount = 0;
|
||||
using (var builder = BuildWebHost<AuthEndPoint>("/auth",
|
||||
using (var builder = BuildWebHost<AuthConnectionHandler>("/auth",
|
||||
options => authCount += options.AuthorizationData.Count))
|
||||
{
|
||||
builder.Start();
|
||||
|
|
@ -42,10 +42,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void MapEndPointFindsAuthAttributeOnInheritedEndPoint()
|
||||
public void MapConnectionHandlerFindsAuthAttributeOnInheritedEndPoint()
|
||||
{
|
||||
var authCount = 0;
|
||||
using (var builder = BuildWebHost<InheritedAuthEndPoint>("/auth",
|
||||
using (var builder = BuildWebHost<InheritedAuthConnectionHandler>("/auth",
|
||||
options => authCount += options.AuthorizationData.Count))
|
||||
{
|
||||
builder.Start();
|
||||
|
|
@ -55,10 +55,10 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void MapEndPointFindsAuthAttributesOnDoubleAuthEndPoint()
|
||||
public void MapConnectionHandlerFindsAuthAttributesOnDoubleAuthEndPoint()
|
||||
{
|
||||
var authCount = 0;
|
||||
using (var builder = BuildWebHost<DoubleAuthEndPoint>("/auth",
|
||||
using (var builder = BuildWebHost<DoubleAuthConnectionHandler>("/auth",
|
||||
options => authCount += options.AuthorizationData.Count))
|
||||
{
|
||||
builder.Start();
|
||||
|
|
@ -69,9 +69,9 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
|
||||
[ConditionalFact]
|
||||
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2, SkipReason = "No WebSockets Client for this platform")]
|
||||
public async Task MapEndPointWithWebSocketSubProtocolSetsProtocol()
|
||||
public async Task MapConnectionHandlerWithWebSocketSubProtocolSetsProtocol()
|
||||
{
|
||||
var host = BuildWebHost<MyEndPoint>("/socket",
|
||||
var host = BuildWebHost<MyConnectionHandler>("/socket",
|
||||
options => options.WebSockets.SubProtocol = "protocol1");
|
||||
|
||||
await host.StartAsync();
|
||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
Assert.Equal(WebSocketMessageType.Close, result.MessageType);
|
||||
}
|
||||
|
||||
private class MyEndPoint : EndPoint
|
||||
private class MyConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override async Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -108,7 +108,7 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private class InheritedAuthEndPoint : AuthEndPoint
|
||||
private class InheritedAuthConnectionHandler : AuthConnectionHandler
|
||||
{
|
||||
public override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -117,12 +117,12 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
|
||||
[Authorize]
|
||||
private class DoubleAuthEndPoint : AuthEndPoint
|
||||
private class DoubleAuthConnectionHandler : AuthConnectionHandler
|
||||
{
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
private class AuthEndPoint : EndPoint
|
||||
private class AuthConnectionHandler : ConnectionHandler
|
||||
{
|
||||
public override Task OnConnectedAsync(ConnectionContext connection)
|
||||
{
|
||||
|
|
@ -130,22 +130,20 @@ namespace Microsoft.AspNetCore.Sockets.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private IWebHost BuildWebHost<TEndPoint>(string path, Action<HttpSocketOptions> configure) where TEndPoint : EndPoint
|
||||
private IWebHost BuildWebHost<TConnectionHandler>(string path, Action<HttpConnectionOptions> configureOptions) where TConnectionHandler : ConnectionHandler
|
||||
{
|
||||
return new WebHostBuilder()
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.UseKestrel()
|
||||
.ConfigureServices(services =>
|
||||
{
|
||||
services.AddSockets();
|
||||
services.AddSingleton<TEndPoint>();
|
||||
services.AddConnections();
|
||||
})
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseSockets(routes =>
|
||||
app.UseConnections(routes =>
|
||||
{
|
||||
routes.MapEndPoint<TEndPoint>(path,
|
||||
httpSocketOptions => configure(httpSocketOptions));
|
||||
routes.MapConnectionHandler<TConnectionHandler>(path, configureOptions);
|
||||
});
|
||||
})
|
||||
.ConfigureLogging(factory =>
|
||||
|
|
@ -8,7 +8,7 @@ using System.Net.WebSockets;
|
|||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Protocols;
|
||||
using Microsoft.AspNetCore.Connections;
|
||||
using Microsoft.AspNetCore.Sockets.Internal.Transports;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
|
|
|
|||
Loading…
Reference in New Issue