From a64940a1f737e8b3717e36df25a6f0ed1dcec2c4 Mon Sep 17 00:00:00 2001 From: John Luo Date: Tue, 25 Apr 2017 10:54:44 -0700 Subject: [PATCH] Remove PreferHostingUrls from options --- .../Internal/WebHost.cs | 2 +- .../Internal/WebHostOptions.cs | 14 +++----------- .../Internal/WebHostUtilities.cs | 17 +++++++++++++++++ .../WebHostConfigurationsTests.cs | 4 +--- 4 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Hosting/Internal/WebHostUtilities.cs diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs index 18cf548932..67163831a4 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHost.cs @@ -261,7 +261,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal var urls = _config[WebHostDefaults.ServerUrlsKey] ?? _config[DeprecatedServerUrlsKey]; if (!string.IsNullOrEmpty(urls)) { - serverAddressesFeature.PreferHostingUrls = _options.PreferHostingUrls; + serverAddressesFeature.PreferHostingUrls = WebHostUtilities.ParseBool(_config, WebHostDefaults.PreferHostingUrlsKey); foreach (var value in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs index 0a5ca14cf9..c58364b453 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostOptions.cs @@ -21,16 +21,15 @@ namespace Microsoft.AspNetCore.Hosting.Internal ApplicationName = configuration[WebHostDefaults.ApplicationKey]; StartupAssembly = configuration[WebHostDefaults.StartupAssemblyKey]; - DetailedErrors = ParseBool(configuration, WebHostDefaults.DetailedErrorsKey); - CaptureStartupErrors = ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey); + DetailedErrors = WebHostUtilities.ParseBool(configuration, WebHostDefaults.DetailedErrorsKey); + CaptureStartupErrors = WebHostUtilities.ParseBool(configuration, WebHostDefaults.CaptureStartupErrorsKey); Environment = configuration[WebHostDefaults.EnvironmentKey]; WebRoot = configuration[WebHostDefaults.WebRootKey]; ContentRootPath = configuration[WebHostDefaults.ContentRootKey]; - PreventHostingStartup = ParseBool(configuration, WebHostDefaults.PreventHostingStartupKey); + PreventHostingStartup = WebHostUtilities.ParseBool(configuration, WebHostDefaults.PreventHostingStartupKey); // Search the primary assembly and configured assemblies. HostingStartupAssemblies = $"{ApplicationName};{configuration[WebHostDefaults.HostingStartupAssembliesKey]}" .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; - PreferHostingUrls = ParseBool(configuration, WebHostDefaults.PreferHostingUrlsKey); var timeout = configuration[WebHostDefaults.ShutdownTimeoutKey]; if (!string.IsNullOrEmpty(timeout) @@ -58,14 +57,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal public string ContentRootPath { get; set; } - public bool PreferHostingUrls { get; set; } - public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromSeconds(5); - private static bool ParseBool(IConfiguration configuration, string key) - { - return string.Equals("true", configuration[key], StringComparison.OrdinalIgnoreCase) - || string.Equals("1", configuration[key], StringComparison.OrdinalIgnoreCase); - } } } \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/WebHostUtilities.cs b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostUtilities.cs new file mode 100644 index 0000000000..49635699d1 --- /dev/null +++ b/src/Microsoft.AspNetCore.Hosting/Internal/WebHostUtilities.cs @@ -0,0 +1,17 @@ +// 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 Microsoft.Extensions.Configuration; + +namespace Microsoft.AspNetCore.Hosting.Internal +{ + public class WebHostUtilities + { + public static bool ParseBool(IConfiguration configuration, string key) + { + return string.Equals("true", configuration[key], StringComparison.OrdinalIgnoreCase) + || string.Equals("1", configuration[key], StringComparison.OrdinalIgnoreCase); + } + } +} diff --git a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs index ab9339496c..5f4291d75e 100644 --- a/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs +++ b/test/Microsoft.AspNetCore.Hosting.Tests/WebHostConfigurationsTests.cs @@ -20,8 +20,7 @@ namespace Microsoft.AspNetCore.Hosting.Tests { "startupAssembly", "MyProjectReference" }, { "environment", "Development"}, { "detailederrors", "true"}, - { "captureStartupErrors", "true" }, - { "preferHostingUrls", "true" } + { "captureStartupErrors", "true" } }; var config = new WebHostOptions(new ConfigurationBuilder().AddInMemoryCollection(parameters).Build()); @@ -32,7 +31,6 @@ namespace Microsoft.AspNetCore.Hosting.Tests Assert.Equal("Development", config.Environment); Assert.True(config.CaptureStartupErrors); Assert.True(config.DetailedErrors); - Assert.True(config.PreferHostingUrls); } [Fact]