From 74a8853e01359a920b1ee0f09c015003353c4ae1 Mon Sep 17 00:00:00 2001 From: Aron Heesakkers Date: Tue, 18 May 2021 10:59:51 +0200 Subject: [PATCH] Add kestral --- Program.cs | 32 ++++++++++++++++++++++++++++---- Startup.cs | 4 ++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index ce600d8..87ee6f1 100644 --- a/Program.cs +++ b/Program.cs @@ -3,7 +3,9 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -18,10 +20,32 @@ public static void Main(string[] args) public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => + + .ConfigureServices((context, services) => + { + services.Configure( + context.Configuration.GetSection("Kestrel")); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.ConfigureKestrel(serverOptions => { - webBuilder.UseStartup() - .UseUrls("http://*:8123"); - }); + serverOptions.Limits.MaxConcurrentConnections = 100; + serverOptions.Limits.MaxConcurrentUpgradedConnections = 100; + serverOptions.Limits.MaxRequestBodySize = 10 * 1024; + serverOptions.Limits.MinRequestBodyDataRate = + new MinDataRate(bytesPerSecond: 100, + gracePeriod: TimeSpan.FromSeconds(10)); + serverOptions.Limits.MinResponseDataRate = + new MinDataRate(bytesPerSecond: 100, + gracePeriod: TimeSpan.FromSeconds(10)); + serverOptions.Limits.KeepAliveTimeout = + TimeSpan.FromDays(30); + serverOptions.Limits.RequestHeadersTimeout = + TimeSpan.FromDays(30); + }) + .UseStartup() + .UseUrls("http://*:8123"); + }); } } diff --git a/Startup.cs b/Startup.cs index 43202fd..037bd52 100644 --- a/Startup.cs +++ b/Startup.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -29,6 +30,9 @@ public Startup(IConfiguration configuration) // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + services.Configure( + Configuration.GetSection("Kestrel")); + Constants.PackageApiUrl = Configuration.GetValue("PackageApiUrl"); Constants.LocationApiUrl = Configuration.GetValue("LocationApiUrl"); Constants.PersonApiUrl = Configuration.GetValue("PersonApiUrl");