From c6fa9793eb345a82bc26597aba8c572414ac14b1 Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Tue, 10 Apr 2018 11:36:36 -0700 Subject: [PATCH] Make Protocols internal --- samples/Http2SampleApp/Program.cs | 3 +-- samples/SampleApp/Startup.cs | 4 ++-- src/Kestrel.Core/ListenOptions.cs | 21 ++----------------- src/Kestrel.Core/Properties/AssemblyInfo.cs | 1 + test/Kestrel.Core.Tests/ListenOptionsTests.cs | 10 --------- .../HttpProtocolSelectionTests.cs | 2 -- 6 files changed, 6 insertions(+), 35 deletions(-) diff --git a/samples/Http2SampleApp/Program.cs b/samples/Http2SampleApp/Program.cs index e95177afe5..6e023ec03d 100644 --- a/samples/Http2SampleApp/Program.cs +++ b/samples/Http2SampleApp/Program.cs @@ -13,8 +13,6 @@ namespace Http2SampleApp { public static void Main(string[] args) { - AppContext.SetSwitch("Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2", isEnabled: true); - var hostBuilder = new WebHostBuilder() .ConfigureLogging((_, factory) => { @@ -31,6 +29,7 @@ namespace Http2SampleApp options.Listen(IPAddress.Any, basePort, listenOptions => { + // This only works becuase InternalsVisibleTo is enabled for this sample. listenOptions.Protocols = HttpProtocols.Http1AndHttp2; listenOptions.UseHttps("testCert.pfx", "testPassword"); listenOptions.UseConnectionLogging(); diff --git a/samples/SampleApp/Startup.cs b/samples/SampleApp/Startup.cs index 3a4f29a3fd..bb070eb348 100644 --- a/samples/SampleApp/Startup.cs +++ b/samples/SampleApp/Startup.cs @@ -68,7 +68,7 @@ namespace SampleApp options.ConfigureEndpointDefaults(opt => { - opt.Protocols = HttpProtocols.Http1; + opt.NoDelay = true; }); options.ConfigureHttpsDefaults(httpsOptions => @@ -129,7 +129,7 @@ namespace SampleApp .Configure(context.Configuration.GetSection("Kestrel")) .Endpoint("NamedEndpoint", opt => { - opt.ListenOptions.Protocols = HttpProtocols.Http1; + opt.ListenOptions.NoDelay = true; }) .Endpoint("NamedHttpsEndpoint", opt => { diff --git a/src/Kestrel.Core/ListenOptions.cs b/src/Kestrel.Core/ListenOptions.cs index dfc15ad1ae..5ae8b31468 100644 --- a/src/Kestrel.Core/ListenOptions.cs +++ b/src/Kestrel.Core/ListenOptions.cs @@ -19,18 +19,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// public class ListenOptions : IEndPointInformation, IConnectionBuilder { - internal const string Http2ExperimentSwitch = "Switch.Microsoft.AspNetCore.Server.Kestrel.Experimental.Http2"; - private FileHandleType _handleType; - private HttpProtocols _protocols = HttpProtocols.Http1; - internal bool _isHttp2Supported; internal readonly List> _middleware = new List>(); internal ListenOptions(IPEndPoint endPoint) { Type = ListenType.IPEndPoint; IPEndPoint = endPoint; - AppContext.TryGetSwitch(Http2ExperimentSwitch, out _isHttp2Supported); } internal ListenOptions(string socketPath) @@ -127,20 +122,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// /// The protocols enabled on this endpoint. /// - /// Defaults to HTTP/1.x only. HTTP/2 support is experimental, see - /// https://go.microsoft.com/fwlink/?linkid=866785 to enable it. - public HttpProtocols Protocols - { - get => _protocols; - set - { - if (!_isHttp2Supported && (value == HttpProtocols.Http1AndHttp2 || value == HttpProtocols.Http2)) - { - throw new NotSupportedException(CoreStrings.Http2NotSupported); - } - _protocols = value; - } - } + /// Defaults to HTTP/1.x only. + internal HttpProtocols Protocols { get; set; } = HttpProtocols.Http1; /// /// Gets the that allows each connection diff --git a/src/Kestrel.Core/Properties/AssemblyInfo.cs b/src/Kestrel.Core/Properties/AssemblyInfo.cs index af17db4f34..793159eefb 100644 --- a/src/Kestrel.Core/Properties/AssemblyInfo.cs +++ b/src/Kestrel.Core/Properties/AssemblyInfo.cs @@ -9,3 +9,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Core.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] [assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] +[assembly: InternalsVisibleTo("Http2SampleApp, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")] diff --git a/test/Kestrel.Core.Tests/ListenOptionsTests.cs b/test/Kestrel.Core.Tests/ListenOptionsTests.cs index 6b4f792f13..77e5a33bbf 100644 --- a/test/Kestrel.Core.Tests/ListenOptionsTests.cs +++ b/test/Kestrel.Core.Tests/ListenOptionsTests.cs @@ -20,16 +20,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.Equal(HttpProtocols.Http1, listenOptions.Protocols); } - [Fact] - public void Http2DisabledByDefault() - { - var listenOptions = new ListenOptions(new IPEndPoint(IPAddress.Loopback, 0)); - var ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http1AndHttp2); - Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); - ex = Assert.Throws(() => listenOptions.Protocols = HttpProtocols.Http2); - Assert.Equal(CoreStrings.Http2NotSupported, ex.Message); - } - [Fact] public void LocalHostListenOptionsClonesConnectionMiddleware() { diff --git a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs index e74c148218..b75496c097 100644 --- a/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs +++ b/test/Kestrel.FunctionalTests/HttpProtocolSelectionTests.cs @@ -50,7 +50,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests { options.Listen(IPAddress.Loopback, 0, listenOptions => { - listenOptions._isHttp2Supported = true; listenOptions.Protocols = serverProtocols; }); }) @@ -81,7 +80,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests .ConfigureLogging(loggingBuilder => loggingBuilder.AddProvider(loggerProvider.Object)) .UseKestrel(options => options.Listen(IPAddress.Loopback, 0, listenOptions => { - listenOptions._isHttp2Supported = true; listenOptions.Protocols = serverProtocols; })) .Configure(app => app.Run(context => Task.CompletedTask));