Add support for Cors (#714)

This commit is contained in:
Stef Heyenrath
2022-01-24 12:26:19 +01:00
committed by GitHub
parent d6c36bc23b
commit ccd433b202
15 changed files with 173 additions and 35 deletions

View File

@@ -293,7 +293,11 @@ namespace WireMock.Server
HandleRequestsSynchronously = _settings.HandleRequestsSynchronously,
ThrowExceptionWhenMatcherFails = _settings.ThrowExceptionWhenMatcherFails,
UseRegexExtended = _settings.UseRegexExtended,
SaveUnmatchedRequests = _settings.SaveUnmatchedRequests
SaveUnmatchedRequests = _settings.SaveUnmatchedRequests,
#if USE_ASPNETCORE
CorsPolicyOptions = _settings.CorsPolicyOptions?.ToString()
#endif
};
return ToJson(model);
@@ -315,6 +319,13 @@ namespace WireMock.Server
_settings.UseRegexExtended = settings.UseRegexExtended;
_settings.SaveUnmatchedRequests = settings.SaveUnmatchedRequests;
#if USE_ASPNETCORE
if (Enum.TryParse<CorsPolicyOptions>(settings.CorsPolicyOptions, true, out var corsPolicyOptions))
{
_settings.CorsPolicyOptions = corsPolicyOptions;
}
#endif
return ResponseMessageBuilder.Create("Settings updated");
}
#endregion Settings

View File

@@ -243,6 +243,8 @@ namespace WireMock.Server
#if USE_ASPNETCORE
_options.AdditionalServiceRegistration = _settings.AdditionalServiceRegistration;
_options.CorsPolicyOptions = _settings.CorsPolicyOptions;
_httpServer = new AspNetCoreSelfHost(_options, urlOptions);
#else
_httpServer = new OwinSelfHost(_options, urlOptions);