mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-19 00:27:04 +01:00
@@ -12,6 +12,7 @@ namespace WireMock.Matchers.Request
|
||||
public class RequestMessageCookieMatcher : IRequestMatcher
|
||||
{
|
||||
private readonly MatchBehaviour _matchBehaviour;
|
||||
private readonly bool _ignoreCase;
|
||||
|
||||
/// <value>
|
||||
/// The funcs.
|
||||
@@ -41,6 +42,7 @@ namespace WireMock.Matchers.Request
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
_ignoreCase = ignoreCase;
|
||||
Name = name;
|
||||
Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) };
|
||||
}
|
||||
@@ -84,9 +86,12 @@ namespace WireMock.Matchers.Request
|
||||
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||
}
|
||||
|
||||
// Check if we want to use IgnoreCase to compare the Cookie-Name and Cookie-Value
|
||||
var cookies = !_ignoreCase ? requestMessage.Cookies : new Dictionary<string, string>(requestMessage.Cookies, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (Funcs != null)
|
||||
{
|
||||
return MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Cookies)));
|
||||
return MatchScores.ToScore(Funcs.Any(f => f(cookies)));
|
||||
}
|
||||
|
||||
if (Matchers == null)
|
||||
@@ -94,12 +99,12 @@ namespace WireMock.Matchers.Request
|
||||
return MatchScores.Mismatch;
|
||||
}
|
||||
|
||||
if (!requestMessage.Cookies.ContainsKey(Name))
|
||||
if (!cookies.ContainsKey(Name))
|
||||
{
|
||||
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||
}
|
||||
|
||||
string value = requestMessage.Cookies[Name];
|
||||
string value = cookies[Name];
|
||||
return Matchers.Max(m => m.IsMatch(value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace WireMock.Matchers.Request
|
||||
public class RequestMessageHeaderMatcher : IRequestMatcher
|
||||
{
|
||||
private readonly MatchBehaviour _matchBehaviour;
|
||||
private readonly bool _ignoreCase;
|
||||
|
||||
/// <summary>
|
||||
/// The functions
|
||||
@@ -43,6 +44,7 @@ namespace WireMock.Matchers.Request
|
||||
Check.NotNull(pattern, nameof(pattern));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
_ignoreCase = ignoreCase;
|
||||
Name = name;
|
||||
Matchers = new IStringMatcher[] { new WildcardMatcher(matchBehaviour, pattern, ignoreCase) };
|
||||
}
|
||||
@@ -60,6 +62,7 @@ namespace WireMock.Matchers.Request
|
||||
Check.NotNull(patterns, nameof(patterns));
|
||||
|
||||
_matchBehaviour = matchBehaviour;
|
||||
_ignoreCase = ignoreCase;
|
||||
Name = name;
|
||||
Matchers = patterns.Select(pattern => new WildcardMatcher(matchBehaviour, pattern, ignoreCase)).Cast<IStringMatcher>().ToArray();
|
||||
}
|
||||
@@ -103,9 +106,12 @@ namespace WireMock.Matchers.Request
|
||||
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||
}
|
||||
|
||||
// Check if we want to use IgnoreCase to compare the Header-Name and Header-Value(s)
|
||||
var headers = !_ignoreCase ? requestMessage.Headers : new Dictionary<string, WireMockList<string>>(requestMessage.Headers, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (Funcs != null)
|
||||
{
|
||||
return MatchScores.ToScore(Funcs.Any(f => f(requestMessage.Headers.ToDictionary(entry => entry.Key, entry => entry.Value.ToArray()))));
|
||||
return MatchScores.ToScore(Funcs.Any(f => f(headers.ToDictionary(entry => entry.Key, entry => entry.Value.ToArray()))));
|
||||
}
|
||||
|
||||
if (Matchers == null)
|
||||
@@ -113,12 +119,12 @@ namespace WireMock.Matchers.Request
|
||||
return MatchScores.Mismatch;
|
||||
}
|
||||
|
||||
if (!requestMessage.Headers.ContainsKey(Name))
|
||||
if (!headers.ContainsKey(Name))
|
||||
{
|
||||
return MatchBehaviourHelper.Convert(_matchBehaviour, MatchScores.Mismatch);
|
||||
}
|
||||
|
||||
WireMockList<string> list = requestMessage.Headers[Name];
|
||||
WireMockList<string> list = headers[Name];
|
||||
return Matchers.Max(m => list.Max(value => m.IsMatch(value))); // TODO : is this correct ?
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user