Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit c599d2a

Browse files
committed
Feedback, renames
1 parent fcf3ec8 commit c599d2a

7 files changed

+51
-28
lines changed

samples/SampleApp/Startup.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,25 @@ public static Task Main(string[] args)
7373
httpsOptions.SslProtocols = SslProtocols.Tls12;
7474
});
7575

76-
options.Configure(context.Configuration.GetSection("Kestrel"))
76+
options
77+
//.Configure()
78+
.Configure(context.Configuration.GetSection("Kestrel"))
7779
.Endpoint("NamedEndpoint", opt =>
7880
{
7981
opt.Listener.Protocols = HttpProtocols.Http1;
8082
})
8183
.Endpoint("NamedHttpsEndpoint", opt =>
8284
{
8385
opt.Https.SslProtocols = SslProtocols.Tls12;
84-
});
86+
})
87+
/*
88+
.Endpoint(IPAddress.Loopback, basePort, options =>
89+
{
90+
})
91+
.LocalhostEndpoint(basePort, options =>
92+
{
93+
})*/
94+
;
8595

8696
// Run callbacks on the transport thread
8797
options.ApplicationSchedulingMode = SchedulingMode.Inline;

src/Kestrel.Core/Internal/IKestrelConfigBuilder.cs renamed to src/Kestrel.Core/Internal/IKestrelConfigurationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
55
{
6-
public interface IKestrelConfigBuilder
6+
public interface IKestrelConfigurationBuilder
77
{
88
void Build();
99
}

src/Kestrel.Core/KestrelServerOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class KestrelServerOptions
6161
/// Provides a configuration source where endpoints will be loaded from on server start.
6262
/// The default is null.
6363
/// </summary>
64-
public IKestrelConfigBuilder ConfigurationBuilder { get; set; }
64+
public IKestrelConfigurationBuilder ConfigurationBuilder { get; set; }
6565

6666
/// <summary>
6767
/// A default configuration action for all endpoints. Use for Listen, configuration, the default url, and URLs.

src/Kestrel.Https/KestrelServerOptionsHttpsExtensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Https
88
{
99
public static class KestrelServerOptionsHttpsExtensions
1010
{
11+
/// <summary>
12+
/// Specifies a configuration Action to run for each newly created https endpoint.
13+
/// </summary>
14+
/// <param name="serverOptions"></param>
15+
/// <param name="configureOptions"></param>
1116
public static void ConfigureHttpsDefaults(this KestrelServerOptions serverOptions, Action<HttpsConnectionAdapterOptions> configureOptions)
1217
{
1318
serverOptions.AdapterData[nameof(ConfigureHttpsDefaults)] = configureOptions;
1419
}
1520

21+
/// <summary>
22+
/// Retrieves the configuration Action specified by ConfigureHttpsDefaults. This method is for infrastructure use only.
23+
/// </summary>
24+
/// <param name="serverOptions"></param>
25+
/// <returns></returns>
1626
public static Action<HttpsConnectionAdapterOptions> GetHttpsDefaults(this KestrelServerOptions serverOptions)
1727
{
1828
if (serverOptions.AdapterData.TryGetValue(nameof(ConfigureHttpsDefaults), out var action))

src/Kestrel/Internal/ConfigReader.cs renamed to src/Kestrel/Internal/ConfigurationReader.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
99
{
10-
internal class ConfigReader
10+
internal class ConfigurationReader
1111
{
1212
private IConfiguration _configuration;
1313
private IList<EndpointConfig> _endpoints;
1414

15-
public ConfigReader(IConfiguration configuration)
15+
public ConfigurationReader(IConfiguration configuration)
1616
{
1717
// May be null
1818
_configuration = configuration;
@@ -43,15 +43,14 @@ private void ReadEndpoints()
4343
var endpointsConfig = _configuration.GetSection("Endpoints").GetChildren();
4444
foreach (var endpointConfig in endpointsConfig)
4545
{
46-
/*
47-
"EndpointName": {
48-
        "Url": "https://*:5463",
49-
        "Certificate": {
50-
          "Path": "testCert.pfx",
51-
          "Password": "testPassword"
52-
       }
53-
}
54-
*/
46+
// "EndpointName": {
47+
        // "Url": "https://*:5463",
48+
        // "Certificate": {
49+
          // "Path": "testCert.pfx",
50+
          // "Password": "testPassword"
51+
       // }
52+
// }
53+
5554
var url = endpointConfig["Url"];
5655
if (string.IsNullOrEmpty(url))
5756
{

src/Kestrel/KestrelConfigBuilder.cs renamed to src/Kestrel/KestrelConfigurationBuilder.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,17 @@
1111
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal;
1212
using Microsoft.AspNetCore.Server.Kestrel.Https;
1313
using Microsoft.AspNetCore.Server.Kestrel.Https.Internal;
14-
using Microsoft.AspNetCore.Server.Kestrel.Internal;
1514
using Microsoft.Extensions.Configuration;
1615
using Microsoft.Extensions.DependencyInjection;
1716

1817
namespace Microsoft.AspNetCore.Server.Kestrel
1918
{
20-
public class KestrelConfigBuilder : IKestrelConfigBuilder
19+
public class KestrelConfigurationBuilder : IKestrelConfigurationBuilder
2120
{
22-
internal KestrelConfigBuilder(KestrelServerOptions options, IConfiguration configuration)
21+
internal KestrelConfigurationBuilder(KestrelServerOptions options, IConfiguration configuration)
2322
{
2423
Options = options ?? throw new ArgumentNullException(nameof(options));
2524
Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
26-
27-
Options.ConfigurationBuilder = this;
2825
}
2926

3027
public KestrelServerOptions Options { get; }
@@ -37,7 +34,7 @@ internal KestrelConfigBuilder(KestrelServerOptions options, IConfiguration confi
3734
/// </summary>
3835
/// <param name="name"></param>
3936
/// <param name="configureOptions"></param>
40-
public KestrelConfigBuilder Endpoint(string name, Action<EndpointConfiguration> configureOptions)
37+
public KestrelConfigurationBuilder Endpoint(string name, Action<EndpointConfiguration> configureOptions)
4138
{
4239
if (string.IsNullOrEmpty(name))
4340
{
@@ -57,7 +54,7 @@ public void Build()
5754
}
5855
Options.ConfigurationBuilder = null;
5956

60-
var configReader = new ConfigReader(Configuration);
57+
var configReader = new ConfigurationReader(Configuration);
6158

6259
foreach (var endpoint in configReader.Endpoints)
6360
{
@@ -72,7 +69,11 @@ public void Build()
7269
Options.GetHttpsDefaults()(httpsOptions);
7370

7471
var certInfo = new CertificateConfig(endpoint.CertConfig);
75-
if (certInfo.IsFileCert)
72+
if (certInfo.IsFileCert && certInfo.IsStoreCert)
73+
{
74+
throw new InvalidOperationException($"The endpoint {endpoint.Name} specified multiple certificate sources.");
75+
}
76+
else if (certInfo.IsFileCert)
7677
{
7778
var env = Options.ApplicationServices.GetRequiredService<IHostingEnvironment>();
7879
httpsOptions.ServerCertificate = new X509Certificate2(Path.Combine(env.ContentRootPath, certInfo.Path), certInfo.Password);
@@ -85,7 +86,7 @@ public void Build()
8586
else if (httpsOptions.ServerCertificate == null)
8687
{
8788
var provider = Options.ApplicationServices.GetRequiredService<IDefaultHttpsProvider>();
88-
httpsOptions.ServerCertificate = provider.Certificate; // May be null
89+
httpsOptions.ServerCertificate = provider.Certificate; // May be null, TODO: Throw
8990
}
9091
}
9192

@@ -96,9 +97,10 @@ public void Build()
9697
configureEndpoint(endpointConfig);
9798
}
9899

99-
if (endpointConfig.Https != null && !listenOptions.ConnectionAdapters.Any(f => f.IsHttps))
100+
// EndpointDefaults or configureEndpoint may have specified an https adapter.
101+
if (https && !listenOptions.ConnectionAdapters.Any(f => f.IsHttps))
100102
{
101-
// It's possible to get here with no cert configured. This will throw.
103+
// TODO: It's possible to get here with no cert configured. This will throw.
102104
listenOptions.UseHttps(endpointConfig.Https);
103105
}
104106

src/Kestrel/KestrelServerOptionsConfigurationExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core
77
{
88
public static class KestrelServerOptionsConfigurationExtensions
99
{
10-
public static KestrelConfigBuilder Configure(this KestrelServerOptions options, IConfiguration config)
10+
public static KestrelConfigurationBuilder Configure(this KestrelServerOptions options, IConfiguration config)
1111
{
12-
return new KestrelConfigBuilder(options, config); // Assigns itself to options.ConfigurationBuilder
12+
var builder = new KestrelConfigurationBuilder(options, config);
13+
options.ConfigurationBuilder = builder;
14+
return builder;
1315
}
1416
}
1517
}

0 commit comments

Comments
 (0)