Skip to content

Commit f21c850

Browse files
committed
Use self-signed certificate by default
1 parent 38c4738 commit f21c850

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/HttpClientTestServer/Program.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ static bool TryConfigureFromCommandLine(string[] args, ServerApplication server)
4949
#pragma warning restore ASP0000 // Do not call 'IServiceCollection.BuildServiceProvider' in 'ConfigureServices'
5050
builder.WebHost.ConfigureKestrel(options =>
5151
{
52-
options.ConfigureHttpsDefaults(options =>
53-
{
54-
options.ServerCertificate = X509CertificateLoader.LoadPkcs12FromFile(Path.Combine(AppContext.BaseDirectory, "Certificates", "localhost.pfx"), null);
55-
});
5652
options.ListenAnyIP(port.Value, listenOptions =>
5753
{
5854
var isSecure = result.GetValue(optionSecure);

src/HttpClientTestServer/ServerApplication.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using HttpClientTestServer.Endpoint;
33
using HttpClientTestServer.Services;
44
using HttpClientTestServer.SessionState;
5+
using Microsoft.Extensions.Options;
6+
using System.Security.Cryptography.X509Certificates;
57

68
namespace HttpClientTestServer;
79

@@ -23,6 +25,17 @@ public ServerApplication(string[] args)
2325
builder = WebApplication.CreateSlimBuilder(args);
2426
}
2527

28+
private void ConfigureKestrelDefaults()
29+
{
30+
builder.WebHost.ConfigureKestrel(options =>
31+
{
32+
options.ConfigureHttpsDefaults(options =>
33+
{
34+
options.ServerCertificate = X509CertificateLoader.LoadPkcs12FromFile(Path.Combine(AppContext.BaseDirectory, "Certificates", "localhost.pfx"), null);
35+
});
36+
});
37+
}
38+
2639
private void ConfigureBuilderDefaults()
2740
{
2841
builder.Services.AddConnectionState();
@@ -80,6 +93,7 @@ public void ConfigureBuilder(Action<WebApplicationBuilder> configure)
8093
public async Task StartAsync()
8194
{
8295
ConfigureBuilderDefaults();
96+
ConfigureKestrelDefaults();
8397

8498
foreach (var c in _configureBuilders)
8599
{

0 commit comments

Comments
 (0)