Also update IWireMockMiddlewareOptions when settings are updated via admin interface (#1166)

* Also update IWireMockMiddlewareOptions when settings are updated via admin interface

* ci
This commit is contained in:
Stef Heyenrath
2024-09-04 18:47:25 +02:00
committed by GitHub
parent 9a49e6a1cd
commit 8348a7b9a3
4 changed files with 45 additions and 30 deletions

View File

@@ -18,6 +18,7 @@ using WireMock.Http;
using WireMock.Logging;
using WireMock.Matchers;
using WireMock.Matchers.Request;
using WireMock.Owin;
using WireMock.RequestBuilders;
using WireMock.ResponseProviders;
using WireMock.Serialization;
@@ -321,29 +322,27 @@ public partial class WireMockServer
InitSettings(_settings);
// _options
if (settings.GlobalProcessingDelay != null)
{
_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
}
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods;
_options.AllowPartialMapping = settings.AllowPartialMapping;
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
_options.MaxRequestLogCount = settings.MaxRequestLogCount;
_options.RequestLogExpirationDuration = settings.RequestLogExpirationDuration;
// _settings & _options
#if USE_ASPNETCORE
if (Enum.TryParse<CorsPolicyOptions>(settings.CorsPolicyOptions, true, out var corsPolicyOptions))
{
_settings.CorsPolicyOptions = corsPolicyOptions;
_options.CorsPolicyOptions = corsPolicyOptions;
}
_options.ClientCertificateMode = _settings.ClientCertificateMode;
_options.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate;
#endif
WireMockMiddlewareOptionsHelper.InitFromSettings(_settings, _options, o =>
{
if (settings.GlobalProcessingDelay != null)
{
o.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
}
#if USE_ASPNETCORE
o.CorsPolicyOptions = corsPolicyOptions;
o.ClientCertificateMode = _settings.ClientCertificateMode;
o.AcceptAnyClientCertificate = _settings.AcceptAnyClientCertificate;
#endif
});
return ResponseMessageBuilder.Create(200, "Settings updated");
}
#endregion Settings

View File

@@ -20,7 +20,6 @@ using WireMock.Exceptions;
using WireMock.Handlers;
using WireMock.Http;
using WireMock.Logging;
using WireMock.Matchers.Request;
using WireMock.Models;
using WireMock.Owin;
using WireMock.RequestBuilders;
@@ -369,9 +368,10 @@ public partial class WireMockServer : IWireMockServer
}
}
WireMockMiddlewareOptionsHelper.InitFromSettings(settings, _options);
_options.LogEntries.CollectionChanged += LogEntries_CollectionChanged;
WireMockMiddlewareOptionsHelper.InitFromSettings(settings, _options, o =>
{
o.LogEntries.CollectionChanged += LogEntries_CollectionChanged;
});
_matcherMapper = new MatcherMapper(_settings);
_mappingConverter = new MappingConverter(_matcherMapper);
@@ -649,13 +649,11 @@ public partial class WireMockServer : IWireMockServer
{
if (settings.AllowBodyForAllHttpMethods == true)
{
_options.AllowBodyForAllHttpMethods = _settings.AllowBodyForAllHttpMethods;
_settings.Logger.Info("AllowBodyForAllHttpMethods is set to True");
}
if (settings.AllowOnlyDefinedHttpStatusCodeInResponse == true)
{
_options.AllowOnlyDefinedHttpStatusCodeInResponse = _settings.AllowOnlyDefinedHttpStatusCodeInResponse;
_settings.Logger.Info("AllowOnlyDefinedHttpStatusCodeInResponse is set to True");
}