Skip to content

Commit

Permalink
Load KestrelServerOptions from configuration, supports Kestrel:AddSer…
Browse files Browse the repository at this point in the history
…verHeader= false
  • Loading branch information
thohng committed Jun 4, 2024
1 parent ba69f61 commit 8bdc630
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/WebApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Azure.Identity;
using Microsoft.AspNetCore.SpaServices;
using Microsoft.Extensions.Options;
using NetLah.Diagnostics;
using NetLah.Extensions.ApplicationInsights;
using NetLah.Extensions.Configuration;
Expand Down Expand Up @@ -56,11 +57,20 @@ void LogAssembly(AssemblyInfo assembly)

builder.CustomApplicationInsightsTelemetry(() => new DefaultAzureCredential());

builder.Services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(builder.Configuration.GetSection("Kestrel"));

builder.AddSpaApp();

var app = builder.Build();
logger.LogInformation("Configure the application...");

var kso = app.Services.GetRequiredService<IOptions<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>>().Value;
#if NET8_0_OR_GREATER
logger.LogInformation("Kestrel options {@options}", new { kso.AddServerHeader, kso.AllowAlternateSchemes, kso.AllowSynchronousIO, kso.AllowResponseHeaderCompression, kso.AllowHostHeaderOverride, kso.DisableStringReuse, kso.Limits });
#else
logger.LogInformation("Kestrel options {@options}", new { kso.AddServerHeader, kso.AllowAlternateSchemes, kso.AllowSynchronousIO, kso.AllowResponseHeaderCompression, kso.DisableStringReuse, kso.Limits });
#endif

app.UseSpaApp(action: app => app.UseSerilogRequestLoggingLevel());

logger.LogInformation("Finished configuring application");
Expand Down
3 changes: 3 additions & 0 deletions src/WebApp/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"wwwroot": "../public",
"Kestrel": {
"AddServerHeader": false
},
"Serilog": {
"MinimumLevel": {
"Default": "Debug"
Expand Down

0 comments on commit 8bdc630

Please sign in to comment.