mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 13:00:33 +01:00
MimePartMatcher does not match multipart/form-data request body (possible bug?) #721
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @BrunoBeraud on GitHub (Oct 24, 2025).
Originally assigned to: @StefH on GitHub.
Hello,
First of all, thank you for this library — it helps us a lot in our development work!
I'm using WireMock.Net.Testcontainers 1.15.0 for our tests and the
sheyenrath/wiremock.net-alpine:1.15.0Docker image in our development environment.We want to define a stub endpoint that accepts a
multipart/form-dataHTTP request.Unfortunately, we’re not able to create a request body matcher using
MimePartMatcherin a JSON mapping file.What Works
This body matcher works correctly:
What Doesn’t Work
When using
MimePartMatcher, even with very lenient matchers, the matcher always returns a 0.0 score for the body:I also tried:
WildcardMatcherwith*for all matchersJsonMatcherwith the exact JSON sentJsonPartialMatcherusing regex (with"Regex": true) and.*for all JSON values"ContentTypeMatcher"with"Name": "ContentTypeMatcher"and"Pattern": "application/json"→ Always a 0.0 score for
BodyMatcher(whilePathMatcher,MethodMatcher, andHeadersMatcherall score 1.0).Request Example
Here’s a sample
curlrequest (exported from Postman):Observation
From the
/__admin/requestsendpoint, here’s an example of the request body WireMock receives:After digging a bit into the code, it seems that the issue comes from the use of the MimeKit library, which appears unable to parse this request body.
As a result, WireMock fails to extract the body parts, and the matcher score stays at its default value (
0.0).Possible Root Cause
It looks like the body content doesn’t include headers (such as
Content-Typewith a boundary) that would allowMimeKitto properly parse it intoBodyParts.In real HTTP requests, this header is not part of the body — it’s in the request headers — which might explain the mismatch compared to the examples in
MimePartMatcherTests, where the content type is included in the body.Question
Could this be a limitation or a bug in how
MimePartMatcher/MimeKithandles real multipart/form-data requests?Or is there a recommended approach to match multipart requests in JSON mappings?
Thank you in advance for your time and for maintaining this great library!
@StefH commented on GitHub (Dec 7, 2025):
@BrunoBeraud
I need to check.
@StefH commented on GitHub (Dec 8, 2025):
@BrunoBeraud
I did check the code and it's correct, in my unit tests I need to pass that text (including Content-Type as part of the body) to get a valid MimeMessage with 3 parts.
The real code will use the Header and prepend this to your body.
I think that your mapping json is wrong.
A possible mapping json for checking 3 parts (same as in the unit test) can be like:
See also this extra unit test --> https://github.com/wiremock/WireMock.Net/pull/1389
@BrunoBeraud commented on GitHub (Dec 17, 2025):
Hello, I have tried your json multipart request mapping file with sheyenrath/wiremock.net-alpine:1.15.0 docker container.
I used this curl request:
curl -X POST http://localhost:8080/multipart \ -F 'plainText=This is some plain text;type=text/plain' \ -F 'jsonData={ "Key": "Value" };type=text/json' \ -F 'image=@image.png;type=image/png'The image is the one expecting in the ExactObjectMatcher base64 pattern
MatchDetails all 1.0 but BodyMatcher still 0.0...
@StefH commented on GitHub (Dec 18, 2025):
@BrunoBeraud
I did not test the Docker image, but just local code.
And the mapping in json is like:
The same mapping in code is:
See also:
https://github.com/wiremock/WireMock.Net/blob/mime-part-matcher/examples/WireMock.Net.Console.NET8/MainApp.cs#L559
The image.png is attached to this comment.

(It's a small red dot below...)
Running CURL on windows:
Logging: