mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-19 00:27:04 +01:00
AllowOnlyDefinedHttpStatusCodeInResponse (#422)
This commit is contained in:
@@ -40,7 +40,7 @@ namespace WireMock.Owin
|
||||
|
||||
bool? AllowBodyForAllHttpMethods { get; set; }
|
||||
|
||||
bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||
bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
|
||||
|
||||
bool? DisableJsonBodyParsing { get; set; }
|
||||
}
|
||||
|
||||
@@ -104,12 +104,12 @@ namespace WireMock.Owin.Mappers
|
||||
|
||||
private int MapStatusCode(int code)
|
||||
{
|
||||
if (_options.AllowAnyHttpStatusCodeInResponse == true || Enum.IsDefined(typeof(HttpStatusCode), code))
|
||||
if (_options.AllowOnlyDefinedHttpStatusCodeInResponse == true && !Enum.IsDefined(typeof(HttpStatusCode), code))
|
||||
{
|
||||
return code;
|
||||
return (int)HttpStatusCode.OK;
|
||||
}
|
||||
|
||||
return (int)HttpStatusCode.OK;
|
||||
return code;
|
||||
}
|
||||
|
||||
private bool IsFault(ResponseMessage responseMessage)
|
||||
|
||||
@@ -43,8 +43,8 @@ namespace WireMock.Owin
|
||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.AllowBodyForAllHttpMethods"/>
|
||||
public bool? AllowBodyForAllHttpMethods { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.AllowAnyHttpStatusCodeInResponse"/>
|
||||
public bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.AllowOnlyDefinedHttpStatusCodeInResponse"/>
|
||||
public bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.DisableResponseBodyParsing"/>
|
||||
public bool? DisableJsonBodyParsing { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Net;
|
||||
using WireMock.Settings;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
@@ -9,6 +10,7 @@ namespace WireMock.ResponseBuilders
|
||||
{
|
||||
/// <summary>
|
||||
/// The with status code.
|
||||
/// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="code">The code.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
@@ -16,6 +18,7 @@ namespace WireMock.ResponseBuilders
|
||||
|
||||
/// <summary>
|
||||
/// The with status code.
|
||||
/// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="code">The code.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
@@ -23,6 +26,7 @@ namespace WireMock.ResponseBuilders
|
||||
|
||||
/// <summary>
|
||||
/// The with status code.
|
||||
/// By default all status codes are allowed, to change this behaviour, see <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="code">The code.</param>
|
||||
/// <returns>The <see cref="IResponseBuilder"/>.</returns>
|
||||
|
||||
@@ -269,10 +269,10 @@ namespace WireMock.Server
|
||||
_settings.Logger.Info("AllowBodyForAllHttpMethods is set to True");
|
||||
}
|
||||
|
||||
if (settings.AllowAnyHttpStatusCodeInResponse == true)
|
||||
if (settings.AllowOnlyDefinedHttpStatusCodeInResponse == true)
|
||||
{
|
||||
_options.AllowAnyHttpStatusCodeInResponse = _settings.AllowAnyHttpStatusCodeInResponse;
|
||||
_settings.Logger.Info("AllowAnyHttpStatusCodeInResponse is set to True");
|
||||
_options.AllowOnlyDefinedHttpStatusCodeInResponse = _settings.AllowOnlyDefinedHttpStatusCodeInResponse;
|
||||
_settings.Logger.Info("AllowOnlyDefinedHttpStatusCodeInResponse is set to True");
|
||||
}
|
||||
|
||||
if (settings.AllowPartialMapping == true)
|
||||
|
||||
@@ -139,10 +139,12 @@ namespace WireMock.Settings
|
||||
bool? AllowBodyForAllHttpMethods { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Allow any HttpStatusCode in the response. Also null, 0, empty or invalid. (default set to false).
|
||||
/// Allow only a HttpStatus Code in the response which is defined. (default set to false).
|
||||
/// - false : also null, 0, empty or invalid HttpStatus codes are allowed.
|
||||
/// - true : only codes defined in <see cref="System.Net.HttpStatusCode"/> are allowed.
|
||||
/// </summary>
|
||||
/// [PublicAPI]
|
||||
bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||
bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Set to true to disable Json deserialization when processing requests. (default set to false).
|
||||
|
||||
@@ -102,8 +102,8 @@ namespace WireMock.Settings
|
||||
[PublicAPI]
|
||||
public bool? AllowBodyForAllHttpMethods { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockServerSettings.AllowAnyHttpStatusCodeInResponse"/>
|
||||
public bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||
/// <inheritdoc cref="IWireMockServerSettings.AllowOnlyDefinedHttpStatusCodeInResponse"/>
|
||||
public bool? AllowOnlyDefinedHttpStatusCodeInResponse { get; set; }
|
||||
|
||||
/// <inheritdoc cref="IWireMockServerSettings.DisableJsonBodyParsing"/>
|
||||
[PublicAPI]
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace WireMock.Settings
|
||||
RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"),
|
||||
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
|
||||
AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"),
|
||||
AllowAnyHttpStatusCodeInResponse = parser.GetBoolValue("AllowAnyHttpStatusCodeInResponse"),
|
||||
AllowOnlyDefinedHttpStatusCodeInResponse = parser.GetBoolValue("AllowOnlyDefinedHttpStatusCodeInResponse"),
|
||||
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing")
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user