Fixed Proxy when using MultipartForm with byte[] (#473)

* wip

* ByteArrayContentHelper

* ByteArrayContentHelperTests
This commit is contained in:
Stef Heyenrath
2020-05-23 16:48:25 +02:00
committed by GitHub
parent d9e3f38fee
commit 1b1ddeab83
5 changed files with 80 additions and 5 deletions

View File

@@ -0,0 +1,30 @@
using System.Net.Http;
using System.Net.Http.Headers;
using JetBrains.Annotations;
using WireMock.Validation;
namespace WireMock.Http
{
internal static class ByteArrayContentHelper
{
/// <summary>
/// Creates a ByteArrayContent object.
/// </summary>
/// <param name="content">The byte[] content (cannot be null)</param>
/// <param name="contentType">The ContentType (can be null)</param>
/// <returns>ByteArrayContent</returns>
internal static ByteArrayContent Create([NotNull] byte[] content, [CanBeNull] MediaTypeHeaderValue contentType)
{
Check.NotNull(content, nameof(content));
var byteContent = new ByteArrayContent(content);
if (contentType != null)
{
byteContent.Headers.Remove(HttpKnownHeaderNames.ContentType);
byteContent.Headers.ContentType = contentType;
}
return byteContent;
}
}
}

View File

@@ -1,10 +1,10 @@
using JetBrains.Annotations;
using Newtonsoft.Json;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using JetBrains.Annotations;
using Newtonsoft.Json;
using WireMock.Types;
using WireMock.Validation;
@@ -29,7 +29,7 @@ namespace WireMock.Http
switch (requestMessage.BodyData?.DetectedBodyType)
{
case BodyType.Bytes:
httpRequestMessage.Content = new ByteArrayContent(requestMessage.BodyData.BodyAsBytes);
httpRequestMessage.Content = ByteArrayContentHelper.Create(requestMessage.BodyData.BodyAsBytes, contentType);
break;
case BodyType.Json:

View File

@@ -64,6 +64,7 @@ namespace WireMock.Owin.Mappers
ContentEncoding = contentEncodingHeader?.FirstOrDefault(),
DecompressGZipAndDeflate = !options.DisableRequestBodyDecompressing.GetValueOrDefault(false)
};
body = await BodyParser.Parse(bodyParserSettings);
}

View File

@@ -130,7 +130,7 @@ namespace WireMock.Util
data.Encoding = encoding;
data.DetectedBodyType = BodyType.String;
}
return data;
}