public static async Task BindAsync(IServerAddressesFeature addresses, KestrelServerOptions serverOptions, ILogger logger, IDefaultHttpsProvider defaultHttpsProvider, Func <ListenOptions, Task> createBinding) { var listenOptions = serverOptions.ListenOptions; var strategy = CreateStrategy( listenOptions.ToArray(), addresses.Addresses.ToArray(), addresses.PreferHostingUrls); var context = new AddressBindContext { Addresses = addresses.Addresses, ListenOptions = listenOptions, ServerOptions = serverOptions, Logger = logger, DefaultHttpsProvider = defaultHttpsProvider ?? UnconfiguredDefaultHttpsProvider.Instance, CreateBinding = createBinding }; // reset options. The actual used options and addresses will be populated // by the address binding feature listenOptions.Clear(); addresses.Addresses.Clear(); await strategy.BindAsync(context).ConfigureAwait(false); }
public KestrelServer(IOptions <KestrelServerOptions> options, ITransportFactory transportFactory, ILoggerFactory loggerFactory, IDefaultHttpsProvider defaultHttpsProvider) : this(transportFactory, CreateServiceContext(options, loggerFactory)) { _defaultHttpsProvider = defaultHttpsProvider; }
internal static ListenOptions ParseAddress(string address, KestrelServerOptions serverOptions, IDefaultHttpsProvider defaultHttpsProvider) { var parsedAddress = ServerAddress.FromUrl(address); var https = false; if (parsedAddress.Scheme.Equals("https", StringComparison.OrdinalIgnoreCase)) { https = true; } else if (!parsedAddress.Scheme.Equals("http", StringComparison.OrdinalIgnoreCase)) { throw new InvalidOperationException(CoreStrings.FormatUnsupportedAddressScheme(address)); } if (!string.IsNullOrEmpty(parsedAddress.PathBase)) { throw new InvalidOperationException(CoreStrings.FormatConfigurePathBaseFromMethodCall($"{nameof(IApplicationBuilder)}.UsePathBase()")); } ListenOptions options = null; if (parsedAddress.IsUnixPipe) { options = new ListenOptions(parsedAddress.UnixPipePath); } else if (string.Equals(parsedAddress.Host, "localhost", StringComparison.OrdinalIgnoreCase)) { // "localhost" for both IPv4 and IPv6 can't be represented as an IPEndPoint. options = new LocalhostListenOptions(parsedAddress.Port); } else if (TryCreateIPEndPoint(parsedAddress, out var endpoint)) { options = new ListenOptions(endpoint); } else { // when address is 'http://hostname:port', 'http://*:port', or 'http://+:port' options = new AnyIPListenOptions(parsedAddress.Port); } if (https) { options.KestrelServerOptions = serverOptions; defaultHttpsProvider.ConfigureHttps(options); } return(options); }
private static KestrelServer CreateServer(KestrelServerOptions options, IDefaultHttpsProvider defaultHttpsProvider, bool throwOnCriticalErrors = true) { return(new KestrelServer(Options.Create(options), new MockTransportFactory(), new LoggerFactory(new[] { new KestrelTestLoggerProvider(throwOnCriticalErrors) }), defaultHttpsProvider)); }