mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
Limits (#457)
This commit is contained in:
40
src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs
Normal file
40
src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#if USE_ASPNETCORE && !NETSTANDARD1_3
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
internal partial class AspNetCoreSelfHost
|
||||
{
|
||||
private static void SetKestrelOptionsLimits(KestrelServerOptions options)
|
||||
{
|
||||
options.Limits.KeepAliveTimeout = TimeSpan.MaxValue;
|
||||
options.Limits.MaxRequestBodySize = null; // https://stackoverflow.com/questions/46738364/increase-upload-request-length-limit-in-kestrel
|
||||
options.Limits.MaxRequestBufferSize = null;
|
||||
options.Limits.MaxRequestHeaderCount = 100;
|
||||
options.Limits.MaxResponseBufferSize = null;
|
||||
options.Limits.RequestHeadersTimeout = TimeSpan.MaxValue;
|
||||
}
|
||||
|
||||
private static void SetHttpsAndUrls(KestrelServerOptions options, ICollection<(string Url, int Port)> urlDetails)
|
||||
{
|
||||
foreach (var detail in urlDetails)
|
||||
{
|
||||
if (detail.Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
options.Listen(System.Net.IPAddress.Any, detail.Port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
options.Listen(System.Net.IPAddress.Any, detail.Port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
32
src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard13.cs
Normal file
32
src/WireMock.Net/Owin/AspNetCoreSelfHost.NETStandard13.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
#if USE_ASPNETCORE && NETSTANDARD1_3
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Server.Kestrel;
|
||||
using WireMock.HttpsCertificate;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
internal partial class AspNetCoreSelfHost
|
||||
{
|
||||
private static void SetKestrelOptionsLimits(KestrelServerOptions options)
|
||||
{
|
||||
options.Limits.KeepAliveTimeout = TimeSpan.MaxValue;
|
||||
options.Limits.MaxRequestBufferSize = null;
|
||||
options.Limits.MaxRequestHeaderCount = 100;
|
||||
options.Limits.MaxResponseBufferSize = null;
|
||||
options.Limits.RequestHeadersTimeout = TimeSpan.MaxValue;
|
||||
}
|
||||
|
||||
private static void SetHttpsAndUrls(KestrelServerOptions options, ICollection<(string Url, int Port)> urlDetails)
|
||||
{
|
||||
var urls = urlDetails.Select(u => u.Url);
|
||||
if (urls.Any(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
options.UseHttps(PublicCertificateHelper.GetX509Certificate2());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -8,7 +8,6 @@ using JetBrains.Annotations;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using WireMock.HttpsCertificate;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Owin.Mappers;
|
||||
using WireMock.Util;
|
||||
@@ -16,7 +15,7 @@ using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Owin
|
||||
{
|
||||
internal class AspNetCoreSelfHost : IOwinSelfHost
|
||||
internal partial class AspNetCoreSelfHost : IOwinSelfHost
|
||||
{
|
||||
private readonly CancellationTokenSource _cts = new CancellationTokenSource();
|
||||
private readonly IWireMockMiddlewareOptions _options;
|
||||
@@ -78,31 +77,9 @@ namespace WireMock.Owin
|
||||
})
|
||||
.UseKestrel(options =>
|
||||
{
|
||||
var urlDetails = _urlOptions.GetDetails();
|
||||
SetKestrelOptionsLimits(options);
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
|
||||
var urls = urlDetails.Select(u => u.Url);
|
||||
if (urls.Any(u => u.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
options.UseHttps(PublicCertificateHelper.GetX509Certificate2());
|
||||
}
|
||||
#else
|
||||
foreach (var detail in urlDetails)
|
||||
{
|
||||
if (detail.Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
options.Listen(System.Net.IPAddress.Any, detail.Port, listenOptions =>
|
||||
{
|
||||
listenOptions.UseHttps(); // PublicCertificateHelper.GetX509Certificate2()
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
options.Listen(System.Net.IPAddress.Any, detail.Port);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
SetHttpsAndUrls(options, _urlOptions.GetDetails());
|
||||
})
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
@@ -144,6 +121,7 @@ namespace WireMock.Owin
|
||||
#elif NET46
|
||||
_logger.Info("WireMock.Net server using .net 4.6.1 or higher");
|
||||
#endif
|
||||
|
||||
#if NETSTANDARD1_3
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user