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)
|
|
|
|
|
{
|
2025-11-16 12:31:25 -06:00
|
|
|
var settings = builder.Configuration.Get<Settings.Settings>();
|
2025-08-10 18:02:25 -05:00
|
|
|
|
2025-11-16 12:31:25 -06: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
|
2025-11-16 12:31:25 -06:00
|
|
|
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;
|
2026-02-17 00:30:27 -06:00
|
|
|
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);
|
|
|
|
|
|
2025-11-16 12:31:25 -06:00
|
|
|
if (settings.Server.Http.UseSSL)
|
2025-03-11 21:21:16 -05:00
|
|
|
{
|
2025-11-16 12:31:25 -06:00
|
|
|
options.Listen(IPAddress.Any, settings.Server.Http.SSLPort, listenOptions =>
|
2025-03-11 21:21:16 -05:00
|
|
|
{
|
2025-11-16 12:31:25 -06: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;
|
|
|
|
|
}
|
|
|
|
|
}
|