Content-Type multipart/form-data header should also be proxied (#1296)

This commit is contained in:
Stef Heyenrath
2025-05-15 18:21:21 +02:00
committed by GitHub
parent baa33552e9
commit 61b6eb8752
4 changed files with 54 additions and 17 deletions

View File

@@ -2,7 +2,6 @@
using System.Net.Http;
using System.Net.Http.Headers;
using Stef.Validation;
namespace WireMock.Http;
@@ -16,8 +15,6 @@ internal static class ByteArrayContentHelper
/// <returns>ByteArrayContent</returns>
internal static ByteArrayContent Create(byte[] content, MediaTypeHeaderValue? contentType)
{
Guard.NotNull(content);
var byteContent = new ByteArrayContent(content);
if (contentType != null)
{

View File

@@ -37,10 +37,11 @@ internal static class HttpRequestMessageHelper
var bodyData = requestMessage.BodyData;
httpRequestMessage.Content = bodyData?.GetBodyType() switch
{
BodyType.Bytes => ByteArrayContentHelper.Create(bodyData!.BodyAsBytes!, contentType),
BodyType.Json => StringContentHelper.Create(JsonConvert.SerializeObject(bodyData!.BodyAsJson), contentType),
BodyType.String => StringContentHelper.Create(bodyData!.BodyAsString!, contentType),
BodyType.FormUrlEncoded => StringContentHelper.Create(bodyData!.BodyAsString!, contentType),
BodyType.Bytes => ByteArrayContentHelper.Create(bodyData.BodyAsBytes!, contentType),
BodyType.Json => StringContentHelper.Create(JsonConvert.SerializeObject(bodyData.BodyAsJson), contentType),
BodyType.String => StringContentHelper.Create(bodyData.BodyAsString!, contentType),
BodyType.FormUrlEncoded => StringContentHelper.Create(bodyData.BodyAsString!, contentType),
BodyType.MultiPart => StringContentHelper.Create(bodyData.BodyAsString!, contentType),
_ => httpRequestMessage.Content
};

View File

@@ -2,7 +2,6 @@
using System.Net.Http;
using System.Net.Http.Headers;
using Stef.Validation;
namespace WireMock.Http;
@@ -16,8 +15,6 @@ internal static class StringContentHelper
/// <returns>StringContent</returns>
internal static StringContent Create(string content, MediaTypeHeaderValue? contentType)
{
Guard.NotNull(content);
var stringContent = new StringContent(content);
stringContent.Headers.ContentType = contentType;
return stringContent;