Make Protocols internal

This commit is contained in:
Chris Ross (ASP.NET) 2018-04-10 11:36:36 -07:00
parent ca44b4adfc
commit c6fa9793eb
6 changed files with 6 additions and 35 deletions

View File

@ -13,8 +13,6 @@ namespace Http2SampleApp
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2", isEnabled: true);
var hostBuilder = new WebHostBuilder() var hostBuilder = new WebHostBuilder()
.ConfigureLogging((_, factory) => .ConfigureLogging((_, factory) =>
{ {
@ -31,6 +29,7 @@ namespace Http2SampleApp
options.Listen(IPAddress.Any, basePort, listenOptions => options.Listen(IPAddress.Any, basePort, listenOptions =>
{ {
// This only works becuase InternalsVisibleTo is enabled for this sample.
listenOptions.Protocols = HttpProtocols.Http1AndHttp2; listenOptions.Protocols = HttpProtocols.Http1AndHttp2;
listenOptions.UseHttps("testCert.pfx", "testPassword"); listenOptions.UseHttps("testCert.pfx", "testPassword");
listenOptions.UseConnectionLogging(); listenOptions.UseConnectionLogging();

View File

@ -68,7 +68,7 @@ namespace SampleApp
options.ConfigureEndpointDefaults(opt => options.ConfigureEndpointDefaults(opt =>
{ {
opt.Protocols = HttpProtocols.Http1; opt.NoDelay = true;
}); });
options.ConfigureHttpsDefaults(httpsOptions => options.ConfigureHttpsDefaults(httpsOptions =>
@ -129,7 +129,7 @@ namespace SampleApp
.Configure(context.Configuration.GetSection("Kestrel")) .Configure(context.Configuration.GetSection("Kestrel"))
.Endpoint("NamedEndpoint", opt => .Endpoint("NamedEndpoint", opt =>
{ {
opt.ListenOptions.Protocols = HttpProtocols.Http1; opt.ListenOptions.NoDelay = true;
}) })
.Endpoint("NamedHttpsEndpoint", opt => .Endpoint("NamedHttpsEndpoint", opt =>
{ {

View File

@ -19,18 +19,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
/// </summary> /// </summary>
public class ListenOptions : IEndPointInformation, IConnectionBuilder public class ListenOptions : IEndPointInformation, IConnectionBuilder
{ {
internal const string Http2ExperimentSwitch = "Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2";
private FileHandleType _handleType; private FileHandleType _handleType;
private HttpProtocols _protocols = HttpProtocols.Http1;
internal bool _isHttp2Supported;
internal readonly List<Func<ConnectionDelegate, ConnectionDelegate>> _middleware = new List<Func<ConnectionDelegate, ConnectionDelegate>>(); internal readonly List<Func<ConnectionDelegate, ConnectionDelegate>> _middleware = new List<Func<ConnectionDelegate, ConnectionDelegate>>();
internal ListenOptions(IPEndPoint endPoint) internal ListenOptions(IPEndPoint endPoint)
{ {
Type = ListenType.IPEndPoint; Type = ListenType.IPEndPoint;
IPEndPoint = endPoint; IPEndPoint = endPoint;
AppContext.TryGetSwitch(Http2ExperimentSwitch, out _isHttp2Supported);
} }
internal ListenOptions(string socketPath) internal ListenOptions(string socketPath)
@ -127,20 +122,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
/// <summary> /// <summary>
/// The protocols enabled on this endpoint. /// The protocols enabled on this endpoint.
/// </summary> /// </summary>
/// <remarks>Defaults to HTTP/1.x only. HTTP/2 support is experimental, see /// <remarks>Defaults to HTTP/1.x only.</remarks>
/// https://go.microsoft.com/fwlink/?linkid=866785 to enable it.</remarks> internal HttpProtocols Protocols { get; set; } = HttpProtocols.Http1;
public HttpProtocols Protocols
{
get => _protocols;
set
{
if (!_isHttp2Supported && (value == HttpProtocols.Http1AndHttp2 || value == HttpProtocols.Http2))
{
throw new NotSupportedException(CoreStrings.Http2NotSupported);
}
_protocols = value;
}
}
/// <summary> /// <summary>
/// Gets the <see cref="List{IConnectionAdapter}"/> that allows each connection <see cref="System.IO.Stream"/> /// Gets the <see cref="List{IConnectionAdapter}"/> that allows each connection <see cref="System.IO.Stream"/>

View File

@ -9,3 +9,4 @@ using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
[assembly: InternalsVisibleTo("Http2SampleApp, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]

View File

@ -20,16 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols); Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols);
} }
[Fact]
public void Http2DisabledByDefault()
{
var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0));
var ex = Assert.Throws<NotSupportedException>(() => listenOptions.Protocols = HttpProtocols.Http1AndHttp2);
Assert.Equal(CoreStrings.Http2NotSupported, ex.Message);
ex = Assert.Throws<NotSupportedException>(() => listenOptions.Protocols = HttpProtocols.Http2);
Assert.Equal(CoreStrings.Http2NotSupported, ex.Message);
}
[Fact] [Fact]
public void LocalHostListenOptionsClonesConnectionMiddleware() public void LocalHostListenOptionsClonesConnectionMiddleware()
{ {

View File

@ -50,7 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
{ {
options.Listen(IPAddress.Loopback, 0, listenOptions => options.Listen(IPAddress.Loopback, 0, listenOptions =>
{ {
listenOptions._isHttp2Supported = true;
listenOptions.Protocols = serverProtocols; listenOptions.Protocols = serverProtocols;
}); });
}) })
@ -81,7 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
.ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object))
.UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions =>
{ {
listenOptions._isHttp2Supported = true;
listenOptions.Protocols = serverProtocols; listenOptions.Protocols = serverProtocols;
})) }))
.Configure(app => app.Run(context => Task.CompletedTask)); .Configure(app => app.Run(context => Task.CompletedTask));