mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-05-30 10:30:45 +02:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e6eb256f5 |
@@ -1,10 +1,3 @@
|
|||||||
# 1.1.10.0 (05 March 2020)
|
|
||||||
- [#427](https://github.com/WireMock-Net/WireMock.Net/pull/427) - Add UsingOptions, UsingConnect and UsingTrace [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#434](https://github.com/WireMock-Net/WireMock.Net/pull/434) - Option to disable JSON deserialization [feature] contributed by [sebastianmattar](https://github.com/sebastianmattar)
|
|
||||||
- [#435](https://github.com/WireMock-Net/WireMock.Net/pull/435) - Also call HandlebarsRegistrationCallback when using WithCallback(..) [feature] contributed by [StefH](https://github.com/StefH)
|
|
||||||
- [#408](https://github.com/WireMock-Net/WireMock.Net/issues/408) - Intermittent threading errors with FindLogEntries [bug]
|
|
||||||
- [#433](https://github.com/WireMock-Net/WireMock.Net/issues/433) - HandlebarsRegistrationCallback not fired [feature]
|
|
||||||
|
|
||||||
# 1.1.9.0 (25 February 2020)
|
# 1.1.9.0 (25 February 2020)
|
||||||
- [#431](https://github.com/WireMock-Net/WireMock.Net/pull/431) - Fix LinqMatcher for JSON int64 [bug] contributed by [StefH](https://github.com/StefH)
|
- [#431](https://github.com/WireMock-Net/WireMock.Net/pull/431) - Fix LinqMatcher for JSON int64 [bug] contributed by [StefH](https://github.com/StefH)
|
||||||
- [#425](https://github.com/WireMock-Net/WireMock.Net/issues/425) - Allow 64 bit numbers in JSON [bug]
|
- [#425](https://github.com/WireMock-Net/WireMock.Net/issues/425) - Allow 64 bit numbers in JSON [bug]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VersionPrefix>1.1.10</VersionPrefix>
|
<VersionPrefix>1.1.9</VersionPrefix>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Choose>
|
<Choose>
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
https://github.com/StefH/GitHubReleaseNotes
|
https://github.com/StefH/GitHubReleaseNotes
|
||||||
|
|
||||||
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.1.10.0
|
GitHubReleaseNotes.exe --output CHANGELOG.md --skip-empty-releases --exclude-labels question invalid doc --version 1.1.9.0
|
||||||
@@ -68,7 +68,7 @@ namespace WireMock.Http
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<ResponseMessage> SendAsync([NotNull] HttpClient client, [NotNull] RequestMessage requestMessage, string url, bool deserializeJson)
|
public static async Task<ResponseMessage> SendAsync([NotNull] HttpClient client, [NotNull] RequestMessage requestMessage, string url)
|
||||||
{
|
{
|
||||||
Check.NotNull(client, nameof(client));
|
Check.NotNull(client, nameof(client));
|
||||||
Check.NotNull(requestMessage, nameof(requestMessage));
|
Check.NotNull(requestMessage, nameof(requestMessage));
|
||||||
@@ -83,7 +83,7 @@ namespace WireMock.Http
|
|||||||
var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead);
|
var httpResponseMessage = await client.SendAsync(httpRequestMessage, HttpCompletionOption.ResponseContentRead);
|
||||||
|
|
||||||
// Create ResponseMessage
|
// Create ResponseMessage
|
||||||
return await HttpResponseMessageHelper.CreateAsync(httpResponseMessage, requiredUri, originalUri, deserializeJson);
|
return await HttpResponseMessageHelper.CreateAsync(httpResponseMessage, requiredUri, originalUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
namespace WireMock.Http
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
|
|
||||||
/// </summary>
|
|
||||||
internal static class HttpRequestMethods
|
|
||||||
{
|
|
||||||
public const string CONNECT = "CONNECT";
|
|
||||||
public const string DELETE = "DELETE";
|
|
||||||
public const string GET = "GET";
|
|
||||||
public const string HEAD = "HEAD";
|
|
||||||
public const string OPTIONS = "OPTIONS";
|
|
||||||
public const string PATCH = "PATCH";
|
|
||||||
public const string POST = "POST";
|
|
||||||
public const string PUT = "PUT";
|
|
||||||
public const string TRACE = "TRACE";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ namespace WireMock.Http
|
|||||||
{
|
{
|
||||||
internal static class HttpResponseMessageHelper
|
internal static class HttpResponseMessageHelper
|
||||||
{
|
{
|
||||||
public static async Task<ResponseMessage> CreateAsync(HttpResponseMessage httpResponseMessage, Uri requiredUri, Uri originalUri, bool deserializeJson)
|
public static async Task<ResponseMessage> CreateAsync(HttpResponseMessage httpResponseMessage, Uri requiredUri, Uri originalUri)
|
||||||
{
|
{
|
||||||
var responseMessage = new ResponseMessage { StatusCode = (int)httpResponseMessage.StatusCode };
|
var responseMessage = new ResponseMessage { StatusCode = (int)httpResponseMessage.StatusCode };
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ namespace WireMock.Http
|
|||||||
contentTypeHeader = headers.First(header => string.Equals(header.Key, HttpKnownHeaderNames.ContentType, StringComparison.OrdinalIgnoreCase)).Value;
|
contentTypeHeader = headers.First(header => string.Equals(header.Key, HttpKnownHeaderNames.ContentType, StringComparison.OrdinalIgnoreCase)).Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
responseMessage.BodyData = await BodyParser.Parse(stream, contentTypeHeader?.FirstOrDefault(), deserializeJson);
|
responseMessage.BodyData = await BodyParser.Parse(stream, contentTypeHeader?.FirstOrDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var header in headers)
|
foreach (var header in headers)
|
||||||
|
|||||||
@@ -41,7 +41,5 @@ namespace WireMock.Owin
|
|||||||
bool? AllowBodyForAllHttpMethods { get; set; }
|
bool? AllowBodyForAllHttpMethods { get; set; }
|
||||||
|
|
||||||
bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||||
|
|
||||||
bool? DisableJsonBodyParsing { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ namespace WireMock.Owin.Mappers
|
|||||||
BodyData body = null;
|
BodyData body = null;
|
||||||
if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
|
if (request.Body != null && BodyParser.ShouldParseBody(method, options.AllowBodyForAllHttpMethods == true))
|
||||||
{
|
{
|
||||||
body = await BodyParser.Parse(request.Body, request.ContentType, !options.DisableJsonBodyParsing.GetValueOrDefault(false));
|
body = await BodyParser.Parse(request.Body, request.ContentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RequestMessage(urldetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
return new RequestMessage(urldetails, method, clientIP, body, headers, cookies) { DateTime = DateTime.UtcNow };
|
||||||
|
|||||||
@@ -45,8 +45,5 @@ namespace WireMock.Owin
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.AllowAnyHttpStatusCodeInResponse"/>
|
/// <inheritdoc cref="IWireMockMiddlewareOptions.AllowAnyHttpStatusCodeInResponse"/>
|
||||||
public bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
public bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockMiddlewareOptions.DisableResponseBodyParsing"/>
|
|
||||||
public bool? DisableJsonBodyParsing { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,13 +9,6 @@ namespace WireMock.RequestBuilders
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IMethodRequestBuilder : IHeadersRequestBuilder
|
public interface IMethodRequestBuilder : IHeadersRequestBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// UsingConnect: add HTTP Method matching on `CONNECT` and matchBehaviour (optional).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder UsingConnect(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UsingDelete: add HTTP Method matching on `DELETE` and matchBehaviour (optional).
|
/// UsingDelete: add HTTP Method matching on `DELETE` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -31,7 +24,7 @@ namespace WireMock.RequestBuilders
|
|||||||
IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UsingHead: Add HTTP Method matching on `HEAD` and matchBehaviour (optional).
|
/// Add HTTP Method matching on `HEAD` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
/// <param name="matchBehaviour">The match behaviour.</param>
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
@@ -51,13 +44,6 @@ namespace WireMock.RequestBuilders
|
|||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UsingPut: add HTTP Method matching on `OPTIONS` and matchBehaviour (optional).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder UsingOptions(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UsingPut: add HTTP Method matching on `PUT` and matchBehaviour (optional).
|
/// UsingPut: add HTTP Method matching on `PUT` and matchBehaviour (optional).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -65,13 +51,6 @@ namespace WireMock.RequestBuilders
|
|||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
||||||
IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UsingTrace: add HTTP Method matching on `TRACE` and matchBehaviour (optional).
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="matchBehaviour">The match behaviour.</param>
|
|
||||||
/// <returns>The <see cref="IRequestBuilder"/>.</returns>
|
|
||||||
IRequestBuilder UsingTrace(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UsingAnyMethod: add HTTP Method matching on any method.
|
/// UsingAnyMethod: add HTTP Method matching on any method.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,113 +0,0 @@
|
|||||||
using System.Linq;
|
|
||||||
using WireMock.Http;
|
|
||||||
using WireMock.Matchers;
|
|
||||||
using WireMock.Matchers.Request;
|
|
||||||
using WireMock.Validation;
|
|
||||||
|
|
||||||
namespace WireMock.RequestBuilders
|
|
||||||
{
|
|
||||||
public partial class Request
|
|
||||||
{
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingConnect(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingConnect(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.CONNECT));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingDelete(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingDelete(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.DELETE));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingGet(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.GET));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingHead(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingHead(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.HEAD));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingOptions(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingOptions(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.OPTIONS));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPost(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingPost(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.POST));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPatch(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.PATCH));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingPut(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.PUT));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingTrace(MatchBehaviour)"/>
|
|
||||||
public IRequestBuilder UsingTrace(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
|
||||||
{
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, HttpRequestMethods.TRACE));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyMethod"/>
|
|
||||||
public IRequestBuilder UsingAnyMethod()
|
|
||||||
{
|
|
||||||
var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
|
|
||||||
foreach (var matcher in matchers)
|
|
||||||
{
|
|
||||||
_requestMatchers.Remove(matcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyVerb"/>
|
|
||||||
public IRequestBuilder UsingAnyVerb()
|
|
||||||
{
|
|
||||||
return UsingAnyMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(string[])"/>
|
|
||||||
public IRequestBuilder UsingMethod(params string[] methods)
|
|
||||||
{
|
|
||||||
return UsingMethod(MatchBehaviour.AcceptOnMatch, methods);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingVerb(string[])"/>
|
|
||||||
public IRequestBuilder UsingVerb(params string[] verbs)
|
|
||||||
{
|
|
||||||
return UsingMethod(verbs);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(MatchBehaviour, string[])"/>
|
|
||||||
public IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, params string[] methods)
|
|
||||||
{
|
|
||||||
Check.NotNullOrEmpty(methods, nameof(methods));
|
|
||||||
|
|
||||||
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, methods));
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -151,5 +151,86 @@ namespace WireMock.RequestBuilders
|
|||||||
_requestMatchers.Add(new RequestMessageUrlMatcher(funcs));
|
_requestMatchers.Add(new RequestMessageUrlMatcher(funcs));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingDelete(MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder UsingDelete(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "DELETE"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingGet(MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder UsingGet(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "GET"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingHead(MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder UsingHead(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "HEAD"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingPost(MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder UsingPost(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "POST"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingPatch(MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder UsingPatch(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "PATCH"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingPut(MatchBehaviour)"/>
|
||||||
|
public IRequestBuilder UsingPut(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch)
|
||||||
|
{
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, "PUT"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyMethod"/>
|
||||||
|
public IRequestBuilder UsingAnyMethod()
|
||||||
|
{
|
||||||
|
var matchers = _requestMatchers.Where(m => m is RequestMessageMethodMatcher).ToList();
|
||||||
|
foreach (var matcher in matchers)
|
||||||
|
{
|
||||||
|
_requestMatchers.Remove(matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingAnyVerb"/>
|
||||||
|
public IRequestBuilder UsingAnyVerb()
|
||||||
|
{
|
||||||
|
return UsingAnyMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(string[])"/>
|
||||||
|
public IRequestBuilder UsingMethod(params string[] methods)
|
||||||
|
{
|
||||||
|
return UsingMethod(MatchBehaviour.AcceptOnMatch, methods);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingVerb(string[])"/>
|
||||||
|
public IRequestBuilder UsingVerb(params string[] verbs)
|
||||||
|
{
|
||||||
|
return UsingMethod(verbs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="IMethodRequestBuilder.UsingMethod(MatchBehaviour, string[])"/>
|
||||||
|
public IRequestBuilder UsingMethod(MatchBehaviour matchBehaviour, params string[] methods)
|
||||||
|
{
|
||||||
|
Check.NotNullOrEmpty(methods, nameof(methods));
|
||||||
|
|
||||||
|
_requestMatchers.Add(new RequestMessageMethodMatcher(matchBehaviour, methods));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,7 +345,7 @@ namespace WireMock.ResponseBuilders
|
|||||||
var proxyUri = new Uri(ProxyUrl);
|
var proxyUri = new Uri(ProxyUrl);
|
||||||
var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery);
|
var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery);
|
||||||
|
|
||||||
return await HttpClientHelper.SendAsync(_httpClientForProxy, requestMessage, proxyUriWithRequestPathAndQuery.AbsoluteUri, !settings.DisableJsonBodyParsing.GetValueOrDefault(false));
|
return await HttpClientHelper.SendAsync(_httpClientForProxy, requestMessage, proxyUriWithRequestPathAndQuery.AbsoluteUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseMessage responseMessage;
|
ResponseMessage responseMessage;
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ namespace WireMock.Server
|
|||||||
var proxyUri = new Uri(settings.ProxyAndRecordSettings.Url);
|
var proxyUri = new Uri(settings.ProxyAndRecordSettings.Url);
|
||||||
var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery);
|
var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery);
|
||||||
|
|
||||||
var responseMessage = await HttpClientHelper.SendAsync(_httpClientForProxy, requestMessage, proxyUriWithRequestPathAndQuery.AbsoluteUri, !settings.DisableJsonBodyParsing.GetValueOrDefault(false));
|
var responseMessage = await HttpClientHelper.SendAsync(_httpClientForProxy, requestMessage, proxyUriWithRequestPathAndQuery.AbsoluteUri);
|
||||||
|
|
||||||
if (HttpStatusRangeParser.IsMatch(settings.ProxyAndRecordSettings.SaveMappingForStatusCodePattern, responseMessage.StatusCode) &&
|
if (HttpStatusRangeParser.IsMatch(settings.ProxyAndRecordSettings.SaveMappingForStatusCodePattern, responseMessage.StatusCode) &&
|
||||||
(settings.ProxyAndRecordSettings.SaveMapping || settings.ProxyAndRecordSettings.SaveMappingToFile))
|
(settings.ProxyAndRecordSettings.SaveMapping || settings.ProxyAndRecordSettings.SaveMappingToFile))
|
||||||
|
|||||||
@@ -213,10 +213,9 @@ namespace WireMock.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
_options.FileSystemHandler = _settings.FileSystemHandler;
|
_options.FileSystemHandler = _settings.FileSystemHandler;
|
||||||
_options.PreWireMockMiddlewareInit = _settings.PreWireMockMiddlewareInit;
|
_options.PreWireMockMiddlewareInit = settings.PreWireMockMiddlewareInit;
|
||||||
_options.PostWireMockMiddlewareInit = _settings.PostWireMockMiddlewareInit;
|
_options.PostWireMockMiddlewareInit = settings.PostWireMockMiddlewareInit;
|
||||||
_options.Logger = _settings.Logger;
|
_options.Logger = _settings.Logger;
|
||||||
_options.DisableJsonBodyParsing = _settings.DisableJsonBodyParsing;
|
|
||||||
|
|
||||||
_matcherMapper = new MatcherMapper(_settings);
|
_matcherMapper = new MatcherMapper(_settings);
|
||||||
_mappingConverter = new MappingConverter(_matcherMapper);
|
_mappingConverter = new MappingConverter(_matcherMapper);
|
||||||
|
|||||||
@@ -143,11 +143,5 @@ namespace WireMock.Settings
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// [PublicAPI]
|
/// [PublicAPI]
|
||||||
bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Set to true to disable Json deserialization when processing requests. (default set to false).
|
|
||||||
/// </summary>
|
|
||||||
[PublicAPI]
|
|
||||||
bool? DisableJsonBodyParsing { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,9 +104,5 @@ namespace WireMock.Settings
|
|||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServerSettings.AllowAnyHttpStatusCodeInResponse"/>
|
/// <inheritdoc cref="IWireMockServerSettings.AllowAnyHttpStatusCodeInResponse"/>
|
||||||
public bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
public bool? AllowAnyHttpStatusCodeInResponse { get; set; }
|
||||||
|
|
||||||
/// <inheritdoc cref="IWireMockServerSettings.DisableJsonBodyParsing"/>
|
|
||||||
[PublicAPI]
|
|
||||||
public bool? DisableJsonBodyParsing { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -35,8 +35,7 @@ namespace WireMock.Settings
|
|||||||
RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"),
|
RequestLogExpirationDuration = parser.GetIntValue("RequestLogExpirationDuration"),
|
||||||
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
|
AllowCSharpCodeMatcher = parser.GetBoolValue("AllowCSharpCodeMatcher"),
|
||||||
AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"),
|
AllowBodyForAllHttpMethods = parser.GetBoolValue("AllowBodyForAllHttpMethods"),
|
||||||
AllowAnyHttpStatusCodeInResponse = parser.GetBoolValue("AllowAnyHttpStatusCodeInResponse"),
|
AllowAnyHttpStatusCodeInResponse = parser.GetBoolValue("AllowAnyHttpStatusCodeInResponse")
|
||||||
DisableJsonBodyParsing = parser.GetBoolValue("DisableJsonBodyParsing")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (logger != null)
|
if (logger != null)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using WireMock.Http;
|
|
||||||
using WireMock.Matchers;
|
using WireMock.Matchers;
|
||||||
using WireMock.Types;
|
using WireMock.Types;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
@@ -31,15 +30,15 @@ namespace WireMock.Util
|
|||||||
*/
|
*/
|
||||||
private static readonly IDictionary<string, bool> BodyAllowedForMethods = new Dictionary<string, bool>
|
private static readonly IDictionary<string, bool> BodyAllowedForMethods = new Dictionary<string, bool>
|
||||||
{
|
{
|
||||||
{ HttpRequestMethods.HEAD, false },
|
{ "HEAD", false },
|
||||||
{ HttpRequestMethods.GET, false },
|
{ "GET", false },
|
||||||
{ HttpRequestMethods.PUT, true },
|
{ "PUT", true },
|
||||||
{ HttpRequestMethods.POST, true },
|
{ "POST", true },
|
||||||
{ HttpRequestMethods.DELETE, true },
|
{ "DELETE", true },
|
||||||
{ HttpRequestMethods.TRACE, false },
|
{ "TRACE", false },
|
||||||
{ HttpRequestMethods.OPTIONS, true },
|
{ "OPTIONS", true },
|
||||||
{ HttpRequestMethods.CONNECT, false },
|
{ "CONNECT", false },
|
||||||
{ HttpRequestMethods.PATCH, true }
|
{ "PATCH", true }
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly IStringMatcher[] MultipartContentTypesMatchers = {
|
private static readonly IStringMatcher[] MultipartContentTypesMatchers = {
|
||||||
@@ -108,7 +107,7 @@ namespace WireMock.Util
|
|||||||
return BodyType.Bytes;
|
return BodyType.Bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<BodyData> Parse([NotNull] Stream stream, [CanBeNull] string contentType = null, bool deserializeJson = true)
|
public static async Task<BodyData> Parse([NotNull] Stream stream, [CanBeNull] string contentType)
|
||||||
{
|
{
|
||||||
Check.NotNull(stream, nameof(stream));
|
Check.NotNull(stream, nameof(stream));
|
||||||
|
|
||||||
@@ -128,6 +127,8 @@ namespace WireMock.Util
|
|||||||
data.BodyAsString = encoding.GetString(data.BodyAsBytes);
|
data.BodyAsString = encoding.GetString(data.BodyAsBytes);
|
||||||
data.Encoding = encoding;
|
data.Encoding = encoding;
|
||||||
data.DetectedBodyType = BodyType.String;
|
data.DetectedBodyType = BodyType.String;
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@@ -141,7 +142,7 @@ namespace WireMock.Util
|
|||||||
data.DetectedBodyType = BodyType.String;
|
data.DetectedBodyType = BodyType.String;
|
||||||
|
|
||||||
// If string is not null or empty, try to deserialize the string to a JObject
|
// If string is not null or empty, try to deserialize the string to a JObject
|
||||||
if (deserializeJson && !string.IsNullOrEmpty(data.BodyAsString))
|
if (!string.IsNullOrEmpty(data.BodyAsString))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,54 +8,18 @@ namespace WireMock.Net.Tests.RequestBuilders
|
|||||||
{
|
{
|
||||||
public class RequestBuilderUsingMethodTests
|
public class RequestBuilderUsingMethodTests
|
||||||
{
|
{
|
||||||
[Fact]
|
|
||||||
public void RequestBuilder_UsingConnect()
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().UsingConnect();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("CONNECT");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestBuilder_UsingOptions()
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().UsingOptions();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("OPTIONS");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_UsingPatch()
|
public void RequestBuilder_UsingPatch()
|
||||||
{
|
{
|
||||||
// Act
|
// Act
|
||||||
var requestBuilder = (Request)Request.Create().UsingPatch();
|
var requestBuilder = (Request)Request.Create().UsingPatch();
|
||||||
|
|
||||||
// Assert
|
// Assert 1
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
Check.That(matchers.Count).IsEqualTo(1);
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("PATCH");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void RequestBuilder_UsingTrace()
|
|
||||||
{
|
|
||||||
// Act
|
|
||||||
var requestBuilder = (Request)Request.Create().UsingTrace();
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
var matchers = requestBuilder.GetPrivateFieldValue<IList<IRequestMatcher>>("_requestMatchers");
|
|
||||||
Check.That(matchers.Count).IsEqualTo(1);
|
|
||||||
Check.That((matchers[0] as RequestMessageMethodMatcher).Methods).ContainsExactly("TRACE");
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
public void RequestBuilder_UsingAnyMethod_ClearsAllOtherMatches()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -243,9 +243,9 @@ namespace WireMock.Net.Tests.RequestMatchers
|
|||||||
// assign
|
// assign
|
||||||
BodyData bodyData;
|
BodyData bodyData;
|
||||||
if (body is byte[] b)
|
if (body is byte[] b)
|
||||||
bodyData = await BodyParser.Parse(new MemoryStream(b), null, true);
|
bodyData = await BodyParser.Parse(new MemoryStream(b), null);
|
||||||
else if (body is string s)
|
else if (body is string s)
|
||||||
bodyData = await BodyParser.Parse(new MemoryStream(Encoding.UTF8.GetBytes(s)), null, true);
|
bodyData = await BodyParser.Parse(new MemoryStream(Encoding.UTF8.GetBytes(s)), null);
|
||||||
else
|
else
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace WireMock.Net.Tests.Util
|
|||||||
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsJson));
|
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsJson));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = await BodyParser.Parse(memoryStream, contentType, true);
|
var body = await BodyParser.Parse(memoryStream, contentType);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(body.BodyAsBytes).IsNotNull();
|
Check.That(body.BodyAsBytes).IsNotNull();
|
||||||
@@ -41,7 +41,7 @@ namespace WireMock.Net.Tests.Util
|
|||||||
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString));
|
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = await BodyParser.Parse(memoryStream, contentType, true);
|
var body = await BodyParser.Parse(memoryStream, contentType);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(body.BodyAsBytes).IsNotNull();
|
Check.That(body.BodyAsBytes).IsNotNull();
|
||||||
@@ -61,23 +61,7 @@ namespace WireMock.Net.Tests.Util
|
|||||||
var memoryStream = new MemoryStream(content);
|
var memoryStream = new MemoryStream(content);
|
||||||
|
|
||||||
// act
|
// act
|
||||||
var body = await BodyParser.Parse(memoryStream, null, true);
|
var body = await BodyParser.Parse(memoryStream, null);
|
||||||
|
|
||||||
// assert
|
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
|
||||||
[InlineData(new byte[] { 34, 97, 34 }, BodyType.String)]
|
|
||||||
[InlineData(new byte[] { 97 }, BodyType.String)]
|
|
||||||
[InlineData(new byte[] { 0xFF, 0xD8, 0xFF, 0xE0 }, BodyType.Bytes)]
|
|
||||||
public async Task BodyParser_Parse_DetectedBodyTypeNoJsonParsing(byte[] content, BodyType detectedBodyType)
|
|
||||||
{
|
|
||||||
// arrange
|
|
||||||
var memoryStream = new MemoryStream(content);
|
|
||||||
|
|
||||||
// act
|
|
||||||
var body = await BodyParser.Parse(memoryStream, null, false);
|
|
||||||
|
|
||||||
// assert
|
// assert
|
||||||
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
Check.That(body.DetectedBodyType).IsEqualTo(detectedBodyType);
|
||||||
@@ -111,7 +95,7 @@ Content-Type: text/html
|
|||||||
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(body));
|
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(body));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await BodyParser.Parse(memoryStream, contentType, true);
|
var result = await BodyParser.Parse(memoryStream, contentType);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.String);
|
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.String);
|
||||||
@@ -131,7 +115,7 @@ Content-Type: text/html
|
|||||||
var memoryStream = new MemoryStream(Encoding.UTF32.GetBytes(body));
|
var memoryStream = new MemoryStream(Encoding.UTF32.GetBytes(body));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await BodyParser.Parse(memoryStream, contentType, true);
|
var result = await BodyParser.Parse(memoryStream, contentType);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
Check.That(result.DetectedBodyType).IsEqualTo(BodyType.Bytes);
|
||||||
@@ -149,7 +133,7 @@ Content-Type: text/html
|
|||||||
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString));
|
var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(bodyAsString));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var body = await BodyParser.Parse(memoryStream, contentType, true);
|
var body = await BodyParser.Parse(memoryStream, contentType);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(body.BodyAsBytes).IsNotNull();
|
Check.That(body.BodyAsBytes).IsNotNull();
|
||||||
|
|||||||
Reference in New Issue
Block a user