HandleRequestsSynchronously (#496)

This commit is contained in:
Stef Heyenrath
2020-08-07 08:08:54 +02:00
committed by GitHub
parent c4ee91c614
commit b55435ddac
10 changed files with 54 additions and 15 deletions

View File

@@ -29,5 +29,10 @@
/// Gets or sets wether to allow a body for all HTTP methods. /// Gets or sets wether to allow a body for all HTTP methods.
/// </summary> /// </summary>
public bool? AllowBodyForAllHttpMethods { get; set; } public bool? AllowBodyForAllHttpMethods { get; set; }
/// <summary>
/// Gets or sets wether to handle all requests synchronously.
/// </summary>
public bool? HandleRequestsSynchronously { get; set; }
} }
} }

View File

@@ -45,5 +45,7 @@ namespace WireMock.Owin
bool? DisableJsonBodyParsing { get; set; } bool? DisableJsonBodyParsing { get; set; }
bool? DisableRequestBodyDecompressing { get; set; } bool? DisableRequestBodyDecompressing { get; set; }
bool? HandleRequestsSynchronously { get; set; }
} }
} }

View File

@@ -25,6 +25,7 @@ namespace WireMock.Owin
{ {
internal class WireMockMiddleware : OwinMiddleware internal class WireMockMiddleware : OwinMiddleware
{ {
private readonly object _lock = new object();
private static readonly Task CompletedTask = Task.FromResult(false); private static readonly Task CompletedTask = Task.FromResult(false);
private readonly IWireMockMiddlewareOptions _options; private readonly IWireMockMiddlewareOptions _options;
private readonly IOwinRequestMapper _requestMapper; private readonly IOwinRequestMapper _requestMapper;
@@ -65,7 +66,17 @@ namespace WireMock.Owin
public Task Invoke(IContext ctx) public Task Invoke(IContext ctx)
#endif #endif
{ {
return InvokeInternal(ctx); if (_options.HandleRequestsSynchronously.GetValueOrDefault(true))
{
lock (_lock)
{
return InvokeInternal(ctx);
}
}
else
{
return InvokeInternal(ctx);
}
} }
private async Task InvokeInternal(IContext ctx) private async Task InvokeInternal(IContext ctx)

View File

@@ -51,5 +51,8 @@ namespace WireMock.Owin
/// <inheritdoc cref="IWireMockMiddlewareOptions.DisableRequestBodyDecompressing"/> /// <inheritdoc cref="IWireMockMiddlewareOptions.DisableRequestBodyDecompressing"/>
public bool? DisableRequestBodyDecompressing { get; set; } public bool? DisableRequestBodyDecompressing { get; set; }
/// <inheritdoc cref="IWireMockMiddlewareOptions.HandleRequestsSynchronously"/>
public bool? HandleRequestsSynchronously { get; set; }
} }
} }

View File

@@ -1,13 +1,13 @@
using System; using System;
using WireMock.Settings; using WireMock.Settings;
namespace WireMock.Server namespace WireMock.Server
{ {
[Obsolete("Use WireMockServer. This will removed in next version (1.3.x)")] [Obsolete("Use WireMockServer. This will removed in next version (1.3.x)")]
public class FluentMockServer : WireMockServer public class FluentMockServer : WireMockServer
{ {
public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings) public FluentMockServer(IFluentMockServerSettings settings) : base((IWireMockServerSettings) settings)
{ {
} }
} }
} }

View File

@@ -344,7 +344,8 @@ namespace WireMock.Server
MaxRequestLogCount = _options.MaxRequestLogCount, MaxRequestLogCount = _options.MaxRequestLogCount,
RequestLogExpirationDuration = _options.RequestLogExpirationDuration, RequestLogExpirationDuration = _options.RequestLogExpirationDuration,
GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds, GlobalProcessingDelay = (int?)_options.RequestProcessingDelay?.TotalMilliseconds,
AllowBodyForAllHttpMethods = _options.AllowBodyForAllHttpMethods AllowBodyForAllHttpMethods = _options.AllowBodyForAllHttpMethods,
HandleRequestsSynchronously = _options.HandleRequestsSynchronously
}; };
return ToJson(model); return ToJson(model);
@@ -371,6 +372,11 @@ namespace WireMock.Server
_options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods.Value; _options.AllowBodyForAllHttpMethods = settings.AllowBodyForAllHttpMethods.Value;
} }
if (settings.HandleRequestsSynchronously != null)
{
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously.Value;
}
return ResponseMessageBuilder.Create("Settings updated"); return ResponseMessageBuilder.Create("Settings updated");
} }
#endregion Settings #endregion Settings

View File

@@ -217,6 +217,7 @@ namespace WireMock.Server
_options.PostWireMockMiddlewareInit = _settings.PostWireMockMiddlewareInit; _options.PostWireMockMiddlewareInit = _settings.PostWireMockMiddlewareInit;
_options.Logger = _settings.Logger; _options.Logger = _settings.Logger;
_options.DisableJsonBodyParsing = _settings.DisableJsonBodyParsing; _options.DisableJsonBodyParsing = _settings.DisableJsonBodyParsing;
_options.HandleRequestsSynchronously = settings.HandleRequestsSynchronously;
_matcherMapper = new MatcherMapper(_settings); _matcherMapper = new MatcherMapper(_settings);
_mappingConverter = new MappingConverter(_matcherMapper); _mappingConverter = new MappingConverter(_matcherMapper);

View File

@@ -143,7 +143,7 @@ namespace WireMock.Settings
/// - false : also null, 0, empty or invalid HttpStatus codes are allowed. /// - false : also null, 0, empty or invalid HttpStatus codes are allowed.
/// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed. /// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed.
/// </summary> /// </summary>
/// [PublicAPI] [PublicAPI]
bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; } bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
/// <summary> /// <summary>
@@ -157,5 +157,11 @@ namespace WireMock.Settings
/// </summary> /// </summary>
[PublicAPI] [PublicAPI]
bool? DisableRequestBodyDecompressing { get; set; } bool? DisableRequestBodyDecompressing { get; set; }
/// <summary>
/// Handle all requests synchronously. (default set to false).
/// </summary>
[PublicAPI]
bool? HandleRequestsSynchronously { get; set; }
} }
} }

View File

@@ -113,5 +113,9 @@ namespace WireMock.Settings
/// <inheritdoc cref="IWireMockServerSettings.DisableRequestBodyDecompressing"/> /// <inheritdoc cref="IWireMockServerSettings.DisableRequestBodyDecompressing"/>
[PublicAPI] [PublicAPI]
public bool? DisableRequestBodyDecompressing { get; set; } public bool? DisableRequestBodyDecompressing { get; set; }
/// <inheritdoc cref="IWireMockServerSettings.HandleRequestsSynchronously"/>
[PublicAPI]
public bool? HandleRequestsSynchronously { get; set; }
} }
} }

View File

@@ -36,7 +36,8 @@ namespace WireMock.Settings
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"), AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"), AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"),
AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue("AllowOnlyDefinedHttpStatusCodeInResponse"), AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue("AllowOnlyDefinedHttpStatusCodeInResponse"),
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing") DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing"),
HandleRequestsSynchronously = parser.GetBoolValue("HandleRequestsSynchronously")
}; };
if (logger != null) if (logger != null)