Skip to content

MimePartMatcher does not match multipart/form-data request body (possible bug?) #1371

@BrunoBeraud

Description

@BrunoBeraud

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.0 Docker image in our development environment.
We want to define a stub endpoint that accepts a multipart/form-data HTTP request.

Unfortunately, we’re not able to create a request body matcher using MimePartMatcher in a JSON mapping file.


What Works

This body matcher works correctly:

"Body": {
  "Matcher": {
    "Name": "RegexMatcher",
    "Pattern": ".+"
  }
}

What Doesn’t Work

When using MimePartMatcher, even with very lenient matchers, the matcher always returns a 0.0 score for the body:

"Body": {
  "Matcher": {
    "Name": "MimePartMatcher",
    "ContentTypeMatcher": {
      "Name": "RegexMatcher",
      "Pattern": ".*"
    },
    "ContentDispositionMatcher": {
      "Name": "RegexMatcher",
      "Pattern": ".*"
    },
    "ContentMatcher": {
      "Name": "RegexMatcher",
      "Pattern": ".*"
    }
  }
}

I also tried:

  • WildcardMatcher with * for all matchers
  • JsonMatcher with the exact JSON sent
  • JsonPartialMatcher using regex (with "Regex": true) and .* for all JSON values
  • Setting "ContentTypeMatcher" with "Name": "ContentTypeMatcher" and "Pattern": "application/json"

→ Always a 0.0 score for BodyMatcher (while PathMatcher, MethodMatcher, and HeadersMatcher all score 1.0).


Request Example

Here’s a sample curl request (exported from Postman):

curl -L -X POST "http://localhost:8080/my-stub-endpoint" \
  -F "metadata=\"{\\\"ID\\\": \\\"9858013b-e020-4ef9-b8a8-0bebc740e6a7\\\", \\\"DATE\\\": \\\"2025-08-15T13:45:30.0000000Z\\\", \\\"NAME\\\": \\\"32c9a8dd-e214-4afb-9611-9cde81f827c6\\\", \\\"NUMBER\\\": 10}\";type=application/json"

Observation

From the /__admin/requests endpoint, here’s an example of the request body WireMock receives:

"Headers": {
        "Accept": [
          "*/*"
        ],
        "Host": [
          "localhost:8080"
        ],
        "User-Agent": [
          "curl/8.13.0"
        ],
        "Content-Type": [
          "multipart/form-data; boundary=------------------------woli8b80pw4vBJtNpAMOKS"
        ],
        "Content-Length": [
          "334"
        ]
      },
"Body": "--------------------------woli8b80pw4vBJtNpAMOKS\r\n
Content-Disposition: form-data; name=\"metadata\"\r\n
Content-Type: application/json\r\n
\r\n
{\"ID\": \"9858013b-e020-4ef9-b8a8-0bebc740e6a7\", \"DATE\": \"2025-08-15T13:45:30.0000000Z\", \"NAME\": \"32c9a8dd-e214-4afb-9611-9cde81f827c6\", \"NUMBER\": 10}\r\n
--------------------------woli8b80pw4vBJtNpAMOKS--\r\n"

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-Type with a boundary) that would allow MimeKit to properly parse it into BodyParts.
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 / MimeKit handles 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!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions