#if NETCORE
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Net;
namespace Apewer.Web
{
/// Kestrel 服务器。
public class KestrelServer : KestrelServer where TStartup : AspNetCoreStartup
{
/// 启动。
public virtual void Run() => Run(false);
}
/// Kestrel 服务器。
public class KestrelServer : AspNetCoreServer
{
/// 配置 WebHost 构建程序。
protected override void Configure(IWebHostBuilder builder) => builder.ConfigureKestrel(Configure);
/// 配置 Kestrel 服务器。
protected virtual void Configure(KestrelServerOptions options)
{
// 同步 IO。
options.AllowSynchronousIO = true;
// 限制请求大小。
options.Limits.MaxRequestBodySize = MaxBody;
// 在 Response 中不包含 Server 属性。
options.AddServerHeader = false;
// 配置端口和证书。
var certificate = Certificate;
if (certificate == null) options.Listen(IPAddress.Any, Port);
else options.Listen(IPAddress.Any, Port, (listen) =>
{
listen.UseHttps(certificate, (ao) =>
{
ao.CheckCertificateRevocation = false;
ao.ServerCertificate = certificate;
ao.AllowAnyClientCertificate();
});
});
}
/// 启动。
public override void Run() => Run(false);
}
}
#endif