Add ability to provide multiple values for headers in response (#59)

* Add ability to provide multiple values for headers

* Updated json model
This commit is contained in:
Oleksandr Liakhevych
2017-10-27 22:49:03 +03:00
committed by Stef Heyenrath
parent a96b7bca1e
commit d134684bcb
27 changed files with 305 additions and 187 deletions

View File

@@ -57,13 +57,13 @@ namespace WireMock.Owin
body = bodyEncoding.GetBytes(bodyAsString);
}
Dictionary<string, string> headers = null;
Dictionary<string, string[]> headers = null;
if (request.Headers.Any())
{
headers = new Dictionary<string, string>();
headers = new Dictionary<string, string[]>();
foreach (var header in request.Headers)
{
headers.Add(header.Key, header.Value.FirstOrDefault());
headers.Add(header.Key, header.Value);
}
}

View File

@@ -35,9 +35,16 @@ namespace WireMock.Owin
if (responseMessage.Headers.ContainsKey(HttpKnownHeaderNames.ContentType))
{
response.ContentType = responseMessage.Headers[HttpKnownHeaderNames.ContentType];
response.ContentType = responseMessage.Headers[HttpKnownHeaderNames.ContentType].FirstOrDefault();
}
responseMessage.Headers.Where(h => h.Key != HttpKnownHeaderNames.ContentType).ToList().ForEach(pair => response.Headers.Append(pair.Key, pair.Value));
var headers = responseMessage.Headers.Where(h => h.Key != HttpKnownHeaderNames.ContentType).ToList();
#if !NETSTANDARD
headers.ForEach(pair => response.Headers.AppendValues(pair.Key, pair.Value.ToArray()));
#else
headers.ForEach(pair => response.Headers.Append(pair.Key, pair.Value.ToArray()));
#endif
if (responseMessage.Body == null && responseMessage.BodyAsBytes == null && responseMessage.BodyAsFile == null)
{
@@ -49,7 +56,7 @@ namespace WireMock.Owin
await response.Body.WriteAsync(responseMessage.BodyAsBytes, 0, responseMessage.BodyAsBytes.Length);
return;
}
if (responseMessage.BodyAsFile != null)
{
byte[] bytes = File.ReadAllBytes(responseMessage.BodyAsFile);

View File

@@ -4,6 +4,7 @@ using WireMock.Logging;
using WireMock.Matchers.Request;
using System.Linq;
using WireMock.Matchers;
using WireMock.Util;
#if !NETSTANDARD
using Microsoft.Owin;
#else
@@ -101,8 +102,8 @@ namespace WireMock.Owin
if (targetMapping.IsAdminInterface && _options.AuthorizationMatcher != null)
{
bool present = request.Headers.TryGetValue("Authorization", out string authorization);
if (!present || _options.AuthorizationMatcher.IsMatch(authorization) < MatchScores.Perfect)
bool present = request.Headers.TryGetValue("Authorization", out WireMockList<string> authorization);
if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect)
{
response = new ResponseMessage { StatusCode = 401 };
return;