Skip to content

Treat multipart bodies as textual for wildcard body matching#162

Merged
dennisdoomen merged 1 commit into
mainfrom
fix-multipart-body-matching
Jul 14, 2026
Merged

Treat multipart bodies as textual for wildcard body matching#162
dennisdoomen merged 1 commit into
mainfrom
fix-multipart-body-matching

Conversation

@dennisdoomen

Copy link
Copy Markdown
Owner

Problem

WithBody(wildcardPattern) matches against RequestInfo.Body, which is only populated when IsBodyLikelyTextual() recognizes the request's content type as textual. Previously this only covered text/* and a fixed list of application/* types.

multipart/mixed bodies (e.g. OData $batch requests) were therefore always treated as binary: Body stayed null while only RawBody was populated. Since WithBody(wildcardPattern) requires request.Body is not null, it could never match a multipart request — even though the multipart envelope itself is plain text.

This surfaced as an UnexpectedRequestException for a previously-passing test that mocked POST .../$batch and matched on body content via WithBody("*fnv_managerportfoliorules*").

Fix

RequestInfo.IsBodyLikelyTextual() now also treats multipart/* content types (e.g. multipart/mixed, multipart/related, multipart/form-data) as textual, so Body is populated for these requests and wildcard/JSON body matching works as expected.

Testing

  • Added Can_match_a_multipart_batch_body_against_a_wildcard_pattern in HttpMockSpecs.cs, exercising WithBody(wildcardPattern) against a MultipartContent request.
  • Full test suite: 195/194 tests passed (net8.0 / net472).
  • API verification tests pass — no public API surface changed.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

WithBody(wildcardPattern) matches against RequestInfo.Body, which was only
populated for a fixed list of textual content types. multipart/mixed bodies
(e.g. OData \ requests) were therefore always treated as binary,
leaving Body null and causing WithBody to never match even though the
multipart envelope itself is text.

IsBodyLikelyTextual() now also recognizes multipart/* content types as
textual, so Body gets populated for these requests too.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Test Results

  3 files  ±0    3 suites  ±0   7s ⏱️ -1s
197 tests +1  197 ✅ +1  0 💤 ±0  0 ❌ ±0 
391 runs  +2  391 ✅ +2  0 💤 ±0  0 ❌ ±0 

Results for commit e13f2c5. ± Comparison against base commit ed30cbe.

♻️ This comment has been updated with latest results.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 29331064810

Warning

No base build found for commit ed30cbe on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 84.827%

Details

  • Patch coverage: 3 of 3 lines across 1 file are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 1504
Covered Lines: 1344
Line Coverage: 89.36%
Relevant Branches: 493
Covered Branches: 350
Branch Coverage: 70.99%
Branches in Coverage %: Yes
Coverage Strength: 338.18 hits per line

💛 - Coveralls

@dennisdoomen dennisdoomen added the bug Something isn't working label Jul 14, 2026
@dennisdoomen
dennisdoomen merged commit 4fe054f into main Jul 14, 2026
10 checks passed
@dennisdoomen
dennisdoomen deleted the fix-multipart-body-matching branch July 14, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants