Compare commits

..

2 Commits
1.8.5 ... 1.8.6

Author SHA1 Message Date
Stef Heyenrath
9b5801f828 1.8.6 2025-05-15 20:16:17 +02:00
Stef Heyenrath
61b6eb8752 Content-Type multipart/form-data header should also be proxied (#1296) 2025-05-15 18:21:21 +02:00
8 changed files with 63 additions and 24 deletions

View File

@@ -1,3 +1,7 @@
# 1.8.6 (15 May 2025)
- [#1296](https://github.com/wiremock/WireMock.Net/pull/1296) - Content-Type multipart/form-data header should also be proxied [bug] contributed by [StefH](https://github.com/StefH)
- [#1295](https://github.com/wiremock/WireMock.Net/issues/1295) - Content-Type `multipart/form-data` header not proxied [bug]
# 1.8.5 (14 May 2025)
- [#1290](https://github.com/wiremock/WireMock.Net/pull/1290) - Use ILRepack to include Microsoft.OpenApi as internal [feature] contributed by [StefH](https://github.com/StefH)
- [#1293](https://github.com/wiremock/WireMock.Net/pull/1293) - Grpc: Fix parsing null value for google.protobuf.Timestamp [bug] contributed by [StefH](https://github.com/StefH)

View File

@@ -4,7 +4,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>1.8.5</VersionPrefix>
<VersionPrefix>1.8.6</VersionPrefix>
<PackageIcon>WireMock.Net-Logo.png</PackageIcon>
<PackageProjectUrl>https://github.com/wiremock/WireMock.Net</PackageProjectUrl>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>

View File

@@ -1,6 +1,6 @@
rem https://github.com/StefH/GitHubReleaseNotes
SET version=1.8.5
SET version=1.8.6
GitHubReleaseNotes --output CHANGELOG.md --skip-empty-releases --exclude-labels wontfix test question invalid doc duplicate example environment --version %version% --token %GH_TOKEN%

View File

@@ -1,7 +1,5 @@
# 1.8.5 (14 May 2025)
- #1290 Use ILRepack to include Microsoft.OpenApi as internal [feature]
- #1293 Grpc: Fix parsing null value for google.protobuf.Timestamp [bug]
- #1275 WithMappingFromOpenApiFile - Support for OpenAPI 3.1.0 [feature]
- #1280 Grpc: breaking changes from 1.6.11 to 1.6.12 [bug]
# 1.8.6 (15 May 2025)
- #1296 Content-Type multipart/form-data header should also be proxied [bug]
- #1295 Content-Type `multipart/form-data` header not proxied [bug]
The full release notes can be found here: https://github.com/wiremock/WireMock.Net/blob/master/CHANGELOG.md

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;

View File

@@ -21,7 +21,7 @@ public class HttpRequestMessageHelperTests
public void HttpRequestMessageHelper_Create()
{
// Assign
var headers = new Dictionary<string, string[]> { { "x", new[] { "value-1" } } };
var headers = new Dictionary<string, string[]> { { "x", ["value-1"] } };
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "PUT", ClientIp, null, headers);
// Act
@@ -91,7 +91,7 @@ public class HttpRequestMessageHelperTests
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson()
{
// Assign
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json" } } };
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/json"] } };
var body = new BodyData
{
BodyAsJson = new { x = 42 },
@@ -111,7 +111,7 @@ public class HttpRequestMessageHelperTests
public async Task HttpRequestMessageHelper_Create_Json_With_ContentType_ApplicationJson_UTF8()
{
// Assign
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/json; charset=utf-8" } } };
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/json; charset=utf-8"] } };
var body = new BodyData
{
BodyAsJson = new { x = 42 },
@@ -131,7 +131,7 @@ public class HttpRequestMessageHelperTests
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml()
{
// Assign
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml" } } };
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/xml"] } };
var body = new BodyData
{
BodyAsString = "<xml>hello</xml>",
@@ -150,7 +150,7 @@ public class HttpRequestMessageHelperTests
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_UTF8()
{
// Assign
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=UTF-8" } } };
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/xml; charset=UTF-8"] } };
var body = new BodyData
{
BodyAsString = "<xml>hello</xml>",
@@ -169,7 +169,7 @@ public class HttpRequestMessageHelperTests
public void HttpRequestMessageHelper_Create_String_With_ContentType_ApplicationXml_ASCII()
{
// Assign
var headers = new Dictionary<string, string[]> { { "Content-Type", new[] { "application/xml; charset=Ascii" } } };
var headers = new Dictionary<string, string[]> { { "Content-Type", ["application/xml; charset=Ascii"] } };
var body = new BodyData
{
BodyAsString = "<xml>hello</xml>",
@@ -184,6 +184,48 @@ public class HttpRequestMessageHelperTests
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("application/xml; charset=Ascii");
}
[Fact]
public async Task HttpRequestMessageHelper_Create_MultiPart_With_ContentType_MultiPartFormData()
{
// Assign
var contentType = "multipart/form-data";
var headers = new Dictionary<string, string[]> { { "Content-Type", [contentType] } };
var body =
"""
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="text"
text default
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file1"; filename="a.txt"
Content-Type: text/plain
Content of a txt
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="file2"; filename="a.html"
Content-Type: text/html
<!DOCTYPE html><title>Content of a.html.</title>
-----------------------------9051914041544843365972754266--
""";
var bodyData = new BodyData
{
BodyAsString = body,
DetectedBodyType = BodyType.String,
DetectedBodyTypeFromContentType = BodyType.MultiPart
};
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), "POST", ClientIp, bodyData, headers);
// Act
var message = HttpRequestMessageHelper.Create(request, "http://url");
// Assert
Check.That(await message.Content.ReadAsStringAsync().ConfigureAwait(false)).Equals(body);
Check.That(message.Content.Headers.GetValues("Content-Type")).ContainsExactly("multipart/form-data");
}
[Theory]
[InlineData("HEAD", true)]
[InlineData("GET", false)]
@@ -199,7 +241,7 @@ public class HttpRequestMessageHelperTests
// Arrange
var key = "Content-Length";
var value = 1234;
var headers = new Dictionary<string, string[]> { { key, new[] { "1234" } } };
var headers = new Dictionary<string, string[]> { { key, ["1234"] } };
var request = new RequestMessage(new UrlDetails("http://localhost/foo"), method, ClientIp, null, headers);
// Act