LANCommander/LANCommander.Server/Startup/Kestrel.cs

42 lines
1.5 KiB
C#
Raw Permalink Normal View History

2025-03-11 21:21:16 -05:00
using System.Net;
using LANCommander.Server.Services.Models;
using Microsoft.AspNetCore.Http.Features;
namespace LANCommander.Server.Startup;
public static class Kestrel
{
public static WebApplicationBuilder ConfigureKestrel(this WebApplicationBuilder builder)
{
var settings = builder.Configuration.Get<Settings.Settings>();
2025-08-10 18:02:25 -05:00
if (settings?.Server.Http.UseSSL ?? false)
builder.WebHost.UseUrls($"http://*:{settings.Server.Http.Port}", $"https://*:{settings.Server.Http.SSLPort}");
2025-08-10 18:02:25 -05:00
else
builder.WebHost.UseUrls($"http://*:{settings.Server.Http.Port}");
2025-08-10 18:02:25 -05:00
2025-03-11 21:21:16 -05:00
builder.WebHost.ConfigureKestrel(options =>
{
options.Limits.MaxRequestBodySize = long.MaxValue;
options.Limits.MaxResponseBufferSize = null; // Unlimited; avoids throttling large file downloads (e.g. game archives)
2025-03-11 21:21:16 -05:00
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(5);
if (settings.Server.Http.UseSSL)
2025-03-11 21:21:16 -05:00
{
options.Listen(IPAddress.Any, settings.Server.Http.SSLPort, listenOptions =>
2025-03-11 21:21:16 -05:00
{
listenOptions.UseHttps(settings.Server.Http.CertificatePath, settings.Server.Http.CertificatePassword);
2025-03-11 21:21:16 -05:00
});
}
});
builder.Services.Configure<FormOptions>(options =>
{
options.MultipartBodyLengthLimit = long.MaxValue;
});
builder.WebHost.UseStaticWebAssets();
return builder;
}
}