Treat multipart bodies as textual for wildcard body matching#162
Merged
Conversation
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>
Coverage Report for CI Build 29331064810Warning No base build found for commit Coverage: 84.827%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
This was referenced Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WithBody(wildcardPattern)matches againstRequestInfo.Body, which is only populated whenIsBodyLikelyTextual()recognizes the request's content type as textual. Previously this only coveredtext/*and a fixed list ofapplication/*types.multipart/mixedbodies (e.g. OData$batchrequests) were therefore always treated as binary:Bodystayednullwhile onlyRawBodywas populated. SinceWithBody(wildcardPattern)requiresrequest.Body is not null, it could never match a multipart request — even though the multipart envelope itself is plain text.This surfaced as an
UnexpectedRequestExceptionfor a previously-passing test that mockedPOST .../$batchand matched on body content viaWithBody("*fnv_managerportfoliorules*").Fix
RequestInfo.IsBodyLikelyTextual()now also treatsmultipart/*content types (e.g.multipart/mixed,multipart/related,multipart/form-data) as textual, soBodyis populated for these requests and wildcard/JSON body matching works as expected.Testing
Can_match_a_multipart_batch_body_against_a_wildcard_patterninHttpMockSpecs.cs, exercisingWithBody(wildcardPattern)against aMultipartContentrequest.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com