diff --git a/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs b/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs index ea9e2a55f3..8f8f78105d 100644 --- a/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs +++ b/benchmarkapps/PlatformBenchmarks/BenchmarkConfigurationHelpers.cs @@ -4,6 +4,7 @@ using System; using System.Net; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; @@ -22,7 +23,7 @@ namespace PlatformBenchmarks var threadCountRaw = builder.GetSetting("threadCount"); int? theadCount = null; - if (!string.IsNullOrEmpty(threadCountRaw) && + if (!string.IsNullOrEmpty(threadCountRaw) && Int32.TryParse(threadCountRaw, out var value)) { theadCount = value; @@ -51,7 +52,7 @@ namespace PlatformBenchmarks return builder; } - + public static IPEndPoint CreateIPEndPoint(this IConfiguration config) { var url = config["server.urls"] ?? config["urls"]; @@ -61,7 +62,7 @@ namespace PlatformBenchmarks return new IPEndPoint(IPAddress.Loopback, 8080); } - var address = ServerAddress.FromUrl(url); + var address = BindingAddress.Parse(url); IPAddress ip; diff --git a/src/Kestrel.Core/Internal/AddressBinder.cs b/src/Kestrel.Core/Internal/AddressBinder.cs index 67ff4f1108..83520f3659 100644 --- a/src/Kestrel.Core/Internal/AddressBinder.cs +++ b/src/Kestrel.Core/Internal/AddressBinder.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting.Server.Features; +using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; using Microsoft.Extensions.Logging; @@ -85,7 +86,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal /// Returns an for the given host an port. /// If the host parameter isn't "localhost" or an IP address, use IPAddress.Any. /// - protected internal static bool TryCreateIPEndPoint(ServerAddress address, out IPEndPoint endpoint) + protected internal static bool TryCreateIPEndPoint(BindingAddress address, out IPEndPoint endpoint) { if (!IPAddress.TryParse(address.Host, out var ip)) { @@ -113,7 +114,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal internal static ListenOptions ParseAddress(string address, out bool https) { - var parsedAddress = ServerAddress.FromUrl(address); + var parsedAddress = BindingAddress.Parse(address); https = false; if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) diff --git a/src/Kestrel.Core/Kestrel.Core.csproj b/src/Kestrel.Core/Kestrel.Core.csproj index 8551a56002..0e3f88127f 100644 --- a/src/Kestrel.Core/Kestrel.Core.csproj +++ b/src/Kestrel.Core/Kestrel.Core.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Kestrel.Core/ServerAddress.cs b/src/Kestrel.Core/ServerAddress.cs index 5650dc6756..4b20374d08 100644 --- a/src/Kestrel.Core/ServerAddress.cs +++ b/src/Kestrel.Core/ServerAddress.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure; namespace Microsoft.AspNetCore.Server.Kestrel.Core { + [Obsolete("This is obsolete and will be removed in a future version. See https://github.com/aspnet/KestrelHttpServer/issues/2230")] public class ServerAddress { public string Host { get; private set; } diff --git a/test/Kestrel.Core.Tests/AddressBinderTests.cs b/test/Kestrel.Core.Tests/AddressBinderTests.cs index 426e490502..74b067cae3 100644 --- a/test/Kestrel.Core.Tests/AddressBinderTests.cs +++ b/test/Kestrel.Core.Tests/AddressBinderTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Connections; +using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; using Microsoft.AspNetCore.Testing; @@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void CorrectIPEndpointsAreCreated(string address, string expectedAddress, int expectedPort) { Assert.True(AddressBinder.TryCreateIPEndPoint( - ServerAddress.FromUrl(address), out var endpoint)); + BindingAddress.Parse(address), out var endpoint)); Assert.NotNull(endpoint); Assert.Equal(IPAddress.Parse(expectedAddress), endpoint.Address); Assert.Equal(expectedPort, endpoint.Port); @@ -42,7 +43,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests public void DoesNotCreateIPEndPointOnInvalidIPAddress(string address) { Assert.False(AddressBinder.TryCreateIPEndPoint( - ServerAddress.FromUrl(address), out var endpoint)); + BindingAddress.Parse(address), out var endpoint)); } [Theory] diff --git a/test/Kestrel.Core.Tests/KestrelServerTests.cs b/test/Kestrel.Core.Tests/KestrelServerTests.cs index 35d08b9ec4..180c7e9bf8 100644 --- a/test/Kestrel.Core.Tests/KestrelServerTests.cs +++ b/test/Kestrel.Core.Tests/KestrelServerTests.cs @@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var exception = Assert.Throws(() => StartDummyApplication(server)); - Assert.Contains("Invalid URL", exception.Message); + Assert.Contains("Invalid url", exception.Message); Assert.Equal(1, testLogger.CriticalErrorsLogged); } } diff --git a/test/Kestrel.Core.Tests/ServerAddressTests.cs b/test/Kestrel.Core.Tests/ServerAddressTests.cs index 94dc2ee3ab..f6e7c45a9e 100644 --- a/test/Kestrel.Core.Tests/ServerAddressTests.cs +++ b/test/Kestrel.Core.Tests/ServerAddressTests.cs @@ -14,7 +14,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("//noscheme")] public void FromUriThrowsForUrlsWithoutSchemeDelimiter(string url) { + #pragma warning disable CS0618 // Type or member is obsolete Assert.Throws(() => ServerAddress.FromUrl(url)); + #pragma warning restore CS0618 // Type or member is obsolete } [Theory] @@ -28,7 +30,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("http:////:5000")] public void FromUriThrowsForUrlsWithoutHost(string url) { + #pragma warning disable CS0618 // Type or member is obsolete Assert.Throws(() => ServerAddress.FromUrl(url)); + #pragma warning restore CS0618 // Type or member is obsolete } [Theory] @@ -56,7 +60,9 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests [InlineData("http://unix:/tmp/kestrel-test.sock:5000/doesn't/matter", "http", "unix:/tmp/kestrel-test.sock", 0, "5000/doesn't/matter", "http://unix:/tmp/kestrel-test.sock")] public void UrlsAreParsedCorrectly(string url, string scheme, string host, int port, string pathBase, string toString) { + #pragma warning disable CS0618 // Type or member is obsolete var serverAddress = ServerAddress.FromUrl(url); + #pragma warning restore CS0618 // Type or member is obsolete Assert.Equal(scheme, serverAddress.Scheme); Assert.Equal(host, serverAddress.Host);