diff --git a/src/Servers/Kestrel/Core/ref/Microsoft.AspNetCore.Server.Kestrel.Core.netcoreapp.cs b/src/Servers/Kestrel/Core/ref/Microsoft.AspNetCore.Server.Kestrel.Core.netcoreapp.cs index 7de1a0907e..f2a23ebbcc 100644 --- a/src/Servers/Kestrel/Core/ref/Microsoft.AspNetCore.Server.Kestrel.Core.netcoreapp.cs +++ b/src/Servers/Kestrel/Core/ref/Microsoft.AspNetCore.Server.Kestrel.Core.netcoreapp.cs @@ -139,6 +139,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core public Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader Configure(Microsoft.Extensions.Configuration.IConfiguration config) { throw null; } public void ConfigureEndpointDefaults(System.Action configureOptions) { } public void ConfigureHttpsDefaults(System.Action configureOptions) { } + public void Listen(System.Net.EndPoint endPoint) { } + public void Listen(System.Net.EndPoint endPoint, System.Action configure) { } public void Listen(System.Net.IPAddress address, int port) { } public void Listen(System.Net.IPAddress address, int port, System.Action configure) { } public void Listen(System.Net.IPEndPoint endPoint) { } @@ -156,6 +158,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core { internal ListenOptions() { } public System.IServiceProvider ApplicationServices { get { throw null; } } + public System.Net.EndPoint EndPoint { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } public ulong FileHandle { get { throw null; } } public System.Net.IPEndPoint IPEndPoint { get { throw null; } } public Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions KestrelServerOptions { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } } diff --git a/src/Servers/Kestrel/Core/src/KestrelServerOptions.cs b/src/Servers/Kestrel/Core/src/KestrelServerOptions.cs index 5cfa303751..ce6cc1451b 100644 --- a/src/Servers/Kestrel/Core/src/KestrelServerOptions.cs +++ b/src/Servers/Kestrel/Core/src/KestrelServerOptions.cs @@ -243,9 +243,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core } /// - /// Bind to given IP endpoint. + /// Bind to the given IP endpoint. /// public void Listen(IPEndPoint endPoint) + { + Listen((EndPoint)endPoint); + } + + /// + /// Bind to the given endpoint. + /// + /// + public void Listen(EndPoint endPoint) { Listen(endPoint, _ => { }); } @@ -255,6 +264,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core /// The callback configures endpoint-specific settings. /// public void Listen(IPEndPoint endPoint, Action configure) + { + Listen((EndPoint)endPoint, configure); + } + + /// + /// Bind to the given endpoint. + /// The callback configures endpoint-specific settings. + /// + public void Listen(EndPoint endPoint, Action configure) { if (endPoint == null) { diff --git a/src/Servers/Kestrel/Core/src/ListenOptions.cs b/src/Servers/Kestrel/Core/src/ListenOptions.cs index 16a8e05477..21fb635d59 100644 --- a/src/Servers/Kestrel/Core/src/ListenOptions.cs +++ b/src/Servers/Kestrel/Core/src/ListenOptions.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core internal readonly List> _middleware = new List>(); internal readonly List> _multiplexedMiddleware = new List>(); - internal ListenOptions(IPEndPoint endPoint) + internal ListenOptions(EndPoint endPoint) { EndPoint = endPoint; } @@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core EndPoint = new FileHandleEndPoint(fileHandle, handleType); } - internal EndPoint EndPoint { get; set; } + public EndPoint EndPoint { get; internal set; } // IPEndPoint is mutable so port 0 can be updated to the bound port. /// diff --git a/src/Servers/Kestrel/Core/test/ListenOptionsTests.cs b/src/Servers/Kestrel/Core/test/ListenOptionsTests.cs index 3eb4626796..6e7412b336 100644 --- a/src/Servers/Kestrel/Core/test/ListenOptionsTests.cs +++ b/src/Servers/Kestrel/Core/test/ListenOptionsTests.cs @@ -1,9 +1,10 @@ // 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.Net; using System.Threading.Tasks; -using Microsoft.AspNetCore.Testing; +using Microsoft.AspNetCore.Connections; using Microsoft.Extensions.DependencyInjection; using Xunit; @@ -45,5 +46,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests Assert.NotNull(serviceProvider); Assert.Same(serviceProvider, clone.ApplicationServices); } + + [Fact] + public void ListenOptionsSupportsAnyEndPoint() + { + var listenOptions = new ListenOptions(new UriEndPoint(new Uri("http://127.0.0.1:5555"))); + Assert.IsType(listenOptions.EndPoint); + Assert.Equal("http://127.0.0.1:5555/", ((UriEndPoint)listenOptions.EndPoint).Uri.ToString()); + } } } diff --git a/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs b/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs index 2ff92f497f..b67e2dfcaa 100644 --- a/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs +++ b/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs @@ -20,6 +20,13 @@ namespace Sockets.BindTests var socketTransportFactory = new SocketTransportFactory(Options.Create(new SocketTransportOptions()), Mock.Of()); await Assert.ThrowsAsync(async () => await socketTransportFactory.BindAsync(new FileHandleEndPoint(0, FileHandleType.Auto))); } + + [Fact] + public async Task ThrowsNotImplementedExceptionWhenBindingToUriEndPoint() + { + var socketTransportFactory = new SocketTransportFactory(Options.Create(new SocketTransportOptions()), Mock.Of()); + await Assert.ThrowsAsync(async () => await socketTransportFactory.BindAsync(new UriEndPoint(new Uri("http://127.0.0.1:5554")))); + } } }