hotfix: fix global distribution notice

This commit is contained in:
Somebody
2024-05-03 18:37:17 +08:00
parent 21c59e6215
commit d0d7a51b7a
2 changed files with 48 additions and 24 deletions

View File

@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Net;
using System.Diagnostics;
namespace EggLink.DanhengServer.WebServer
{
@@ -13,25 +14,32 @@ namespace EggLink.DanhengServer.WebServer
BuildWebHost(args, port, address).Start();
}
public static IWebHost BuildWebHost(string[] args, int port, string address) =>
WebHost.CreateDefaultBuilder(args)
public static IWebHost BuildWebHost(string[] args, int port, string address)
{
var b = WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
.ConfigureLogging((hostingContext, logging) =>
{
options.Listen(IPAddress.Any, port, listenOptions =>
{
listenOptions.UseHttps(
ConfigManager.Config.KeyStore.KeyStorePath,
ConfigManager.Config.KeyStore.KeyStorePassword
);
});
})
.ConfigureLogging((hostingContext, logging) =>
{
logging.ClearProviders();
})
.UseUrls(address)
.Build();
.UseUrls(address);
if (ConfigManager.Config.HttpServer.UseSSL)
{
b.UseKestrel(options =>
{
options.Listen(IPAddress.Any, port, listenOptions =>
{
listenOptions.UseHttps(
ConfigManager.Config.KeyStore.KeyStorePath,
ConfigManager.Config.KeyStore.KeyStorePassword
);
});
});
}
return b.Build();
}
}
public class Startup
@@ -48,6 +56,22 @@ namespace EggLink.DanhengServer.WebServer
app.UseDeveloperExceptionPage();
}
app.Use(async (context, next) =>
{
using var buffer = new MemoryStream();
var request = context.Request;
var response = context.Response;
var bodyStream = response.Body;
response.Body = buffer;
await next.Invoke();
buffer.Position = 0;
context.Response.Headers["Content-Length"] = (response.ContentLength ?? buffer.Length).ToString();
context.Response.Headers.Remove("Transfer-Encoding");
await buffer.CopyToAsync(bodyStream);
});
app.UseHttpsRedirection();
app.UseRouting();