Post request with "BodyAsBytes" is not matched by RegexMatcher #354

Closed
opened 2025-12-29 08:26:47 +01:00 by adam · 5 comments
Owner

Originally created by @FSatmar on GitHub (Aug 4, 2021).

Describe the bug

When a mapping is in place for a Post request with Body RegexMatcher = ".*" and a request with "BodyAsBytes" is made, the mapping is not returned.

Expected behavior:

The mapping should be returned since the RegexMatcher should match any body content.

Test to reproduce

  • 1 create Post mapping with RegexMatcher = ".*"
  • 2 make request with "BodyAsBytes"

Please see attached files for examples of mapping and requests. Note that Request1with String body type works, while Request2 with BodyAsBytes fails.
Mapping.txt
Request1.txt
Request2.txt
Also note that this used to work fine in version 1.0.9.

Originally created by @FSatmar on GitHub (Aug 4, 2021). ### Describe the bug When a mapping is in place for a Post request with Body RegexMatcher = ".*" and a request with "BodyAsBytes" is made, the mapping is not returned. ### Expected behavior: The mapping should be returned since the RegexMatcher should match any body content. ### Test to reproduce - 1 create Post mapping with RegexMatcher = ".*" - 2 make request with "BodyAsBytes" ### Other related info Please see attached files for examples of mapping and requests. Note that Request1with String body type works, while Request2 with BodyAsBytes fails. [Mapping.txt](https://github.com/WireMock-Net/WireMock.Net/files/6930963/Mapping.txt) [Request1.txt](https://github.com/WireMock-Net/WireMock.Net/files/6930967/Request1.txt) [Request2.txt](https://github.com/WireMock-Net/WireMock.Net/files/6930970/Request2.txt) Also note that this used to work fine in version 1.0.9.
adam added the bug label 2025-12-29 08:26:47 +01:00
adam closed this issue 2025-12-29 08:26:47 +01:00
Author
Owner

@StefH commented on GitHub (Aug 4, 2021):

Hello @FSatmar ,

I understand your point, however when the body is just bytes, a RegExMatcher/WildcardMatcher (= StringMatcher) cannot be used because I never know if the bytes area actually a string (and which encoding is used).

So I think what could be a solution for you is that a new matcher like AnyBytesMatcher will be added, which can be used to detect if the body contains any bytes.

Another option would be to update the ExactObjectMatcher which can take a base64 string which defines the exact body you want to match.

@StefH commented on GitHub (Aug 4, 2021): Hello @FSatmar , I understand your point, however when the body is just bytes, a RegExMatcher/WildcardMatcher (= StringMatcher) cannot be used because I never know if the bytes area actually a string (and which encoding is used). So I think what could be a solution for you is that a new matcher like `AnyBytesMatcher` will be added, which can be used to detect if the body contains any bytes. Another option would be to update the `ExactObjectMatcher` which can take a base64 string which defines the exact body you want to match.
Author
Owner

@FSatmar commented on GitHub (Aug 4, 2021):

Is there an option to define a matcher that would match any type of body and any content? as in this case I don't care about the body content. otherwise, it seems I'll need to create 2 mappings, one for each body type.

@FSatmar commented on GitHub (Aug 4, 2021): Is there an option to define a matcher that would match any type of body and any content? as in this case I don't care about the body content. otherwise, it seems I'll need to create 2 mappings, one for each body type.
Author
Owner

@StefH commented on GitHub (Aug 4, 2021):

I've added a NotNullOrEmptyMatcher which should be possible to use for string, json and bytes.

Try the MyGet preview version: 1.4.19-ci-15242.

https://github.com/WireMock-Net/WireMock.Net/pull/625

@StefH commented on GitHub (Aug 4, 2021): I've added a `NotNullOrEmptyMatcher` which should be possible to use for string, json and bytes. Try the MyGet preview version: `1.4.19-ci-15242`. https://github.com/WireMock-Net/WireMock.Net/pull/625
Author
Owner

@FSatmar commented on GitHub (Aug 4, 2021):

I've added a NotNullOrEmptyMatcher which should be possible to use for string, json and bytes.

Try the MyGet preview version: 1.4.19-ci-15242.

#625

This works great, thank you very much!

@FSatmar commented on GitHub (Aug 4, 2021): > > > I've added a `NotNullOrEmptyMatcher` which should be possible to use for string, json and bytes. > > Try the MyGet preview version: `1.4.19-ci-15242`. > > #625 This works great, thank you very much!
Author
Owner

@StefH commented on GitHub (Aug 4, 2021):

@FSatmar OK

I'll merge the PR and create a new official version in some time.

@StefH commented on GitHub (Aug 4, 2021): @FSatmar OK I'll merge the PR and create a new official version in some time.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#354