[PR #334] [MERGED] Fix issues with Proxy mode and Binary Request Bodies #864

Closed
opened 2025-12-29 15:33:46 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/wiremock/WireMock.Net/pull/334
Author: @andi0b
Created: 8/26/2019
Status: Merged
Merged: 9/1/2019
Merged by: @StefH

Base: masterHead: master


📝 Commits (9)

  • 5c17761 Add Test for Proxy with binary request
  • 3c7e406 Fix binary parsing in BodyParser
  • 4606fe3 Fix binary Matching in RequestMessageBodyMatcher
  • b35162a Improved Binary Matching in RequestMessageBodyMatcher
  • ba88b61 BodyParser: Add test for Content Autodetection
  • d78da76 RequestMessageBodyMatcherTests: Make Code more pretty :)
  • 21aaa5a BodyParserChanges: Revert white space changes
  • 8bd7cbd Upstream merge
  • 3ff44ad Fixed test for different behavior in request matching

📊 Changes

6 files changed (+135 additions, -7 deletions)

View changed files

📝 src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs (+3 -3)
📝 src/WireMock.Net/Util/BodyParser.cs (+2 -2)
📝 test/WireMock.Net.Tests/FluentMockServerTests.Proxy.cs (+38 -0)
📝 test/WireMock.Net.Tests/FluentMockServerTests.cs (+1 -1)
📝 test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs (+75 -1)
📝 test/WireMock.Net.Tests/Util/BodyParserTests.cs (+16 -0)

📄 Description

We used Wiremocks.NET in Proxy mode to sometimes test against the real API and sometimes just mock it. This stopped working when we started POSTing JPEGs. The body was altered because WireMocks.NET started to parse the binary content as UTF8 and converted it back. This causes issues with binary contents, you can see it because the length changes.

This pull request contains:

  • Test to show this issue
  • Fix for this issue (by replacing Encoding.UTF8 with another UTF8 decoder which throws Exceptions on unmappable characters, so the code can fallback to binary parsing)
  • Another fix in RequestMessageBodyMatcher I discovered because my test didn't work correctly. (Enable binary matching also if the content is detected as string or JSON).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/wiremock/WireMock.Net/pull/334 **Author:** [@andi0b](https://github.com/andi0b) **Created:** 8/26/2019 **Status:** ✅ Merged **Merged:** 9/1/2019 **Merged by:** [@StefH](https://github.com/StefH) **Base:** `master` ← **Head:** `master` --- ### 📝 Commits (9) - [`5c17761`](https://github.com/wiremock/WireMock.Net/commit/5c177615a4d042e15a809979dc6f2362ed1ef6a7) Add Test for Proxy with binary request - [`3c7e406`](https://github.com/wiremock/WireMock.Net/commit/3c7e406d5eed346d9bcce10c55981b55edf71fa0) Fix binary parsing in BodyParser - [`4606fe3`](https://github.com/wiremock/WireMock.Net/commit/4606fe393ddc898607cdb23777a1b9abab46e11f) Fix binary Matching in RequestMessageBodyMatcher - [`b35162a`](https://github.com/wiremock/WireMock.Net/commit/b35162a2a1097cbc4ccbf1f354552758d48eed28) Improved Binary Matching in RequestMessageBodyMatcher - [`ba88b61`](https://github.com/wiremock/WireMock.Net/commit/ba88b616152c60aa707d90724715a683ce658a8f) BodyParser: Add test for Content Autodetection - [`d78da76`](https://github.com/wiremock/WireMock.Net/commit/d78da76bec24c60a11a2a4dddfe1f2f0de446b05) RequestMessageBodyMatcherTests: Make Code more pretty :) - [`21aaa5a`](https://github.com/wiremock/WireMock.Net/commit/21aaa5adf3b7633e92cd570cb01a2345b249e6d9) BodyParserChanges: Revert white space changes - [`8bd7cbd`](https://github.com/wiremock/WireMock.Net/commit/8bd7cbd54390fec6d4b177e56362f2080e44c2c4) Upstream merge - [`3ff44ad`](https://github.com/wiremock/WireMock.Net/commit/3ff44adb63ae4da58e3e9912ce7758a2bc7f3f8b) Fixed test for different behavior in request matching ### 📊 Changes **6 files changed** (+135 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/WireMock.Net/Matchers/Request/RequestMessageBodyMatcher.cs` (+3 -3) 📝 `src/WireMock.Net/Util/BodyParser.cs` (+2 -2) 📝 `test/WireMock.Net.Tests/FluentMockServerTests.Proxy.cs` (+38 -0) 📝 `test/WireMock.Net.Tests/FluentMockServerTests.cs` (+1 -1) 📝 `test/WireMock.Net.Tests/RequestMatchers/RequestMessageBodyMatcherTests.cs` (+75 -1) 📝 `test/WireMock.Net.Tests/Util/BodyParserTests.cs` (+16 -0) </details> ### 📄 Description We used Wiremocks.NET in Proxy mode to sometimes test against the real API and sometimes just mock it. This stopped working when we started POSTing JPEGs. The body was altered because WireMocks.NET started to parse the binary content as UTF8 and converted it back. This causes issues with binary contents, you can see it because the length changes. This pull request contains: - Test to show this issue - Fix for this issue (by replacing Encoding.UTF8 with another UTF8 decoder which throws Exceptions on unmappable characters, so the code can fallback to binary parsing) - Another fix in RequestMessageBodyMatcher I discovered because my test didn't work correctly. (Enable binary matching also if the content is detected as string or JSON). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 15:33:46 +01:00
adam closed this issue 2025-12-29 15:33:47 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#864