How to get matched mapping by HttpRequest or HttpRequestMessage #424

Closed
opened 2025-12-29 15:23:33 +01:00 by adam · 10 comments
Owner

Originally created by @marspox on GitHub (Jul 12, 2022).

Originally assigned to: @StefH on GitHub.

Hello,
I would like to know wheather is it possible to get mapping by HttpRequest or HttpRequestMessage.
Let's say that I have HttpRequest/HttpRequestMessage object then based on its values I would like to find out which mapping will be matched for that request.

Originally created by @marspox on GitHub (Jul 12, 2022). Originally assigned to: @StefH on GitHub. Hello, I would like to know wheather is it possible to get mapping by HttpRequest or HttpRequestMessage. Let's say that I have HttpRequest/HttpRequestMessage object then based on its values I would like to find out which mapping will be matched for that request.
adam added the feature label 2025-12-29 15:23:33 +01:00
adam closed this issue 2025-12-29 15:23:33 +01:00
Author
Owner

@StefH commented on GitHub (Jul 12, 2022):

@marspox
It's not possible yet to analyze a HttpRequest or HttpRequestMessage to see which mapping will be matched.

The only way now it is to send the HttpRequest or HttpRequestMessage to WireMock.Net and see if the response is valid and you can verify the matched mappings.

@StefH commented on GitHub (Jul 12, 2022): @marspox It's not possible yet to analyze a HttpRequest or HttpRequestMessage to see which mapping will be matched. The only way now it is to send the HttpRequest or HttpRequestMessage to WireMock.Net and see if the response is valid and you can verify the matched mappings.
Author
Owner

@marspox commented on GitHub (Jul 12, 2022):

I see, but after sending HttpRequest I still don't know which mapping has been applied to get response.
I'm writing a tool which uses WireMock.Net with proxy recording. After sending a request, mapping is automatically created if missing, I would like to get mapping or its guid in order to cache new mappings.
It would be great to have such metod in public partial class WireMockServer : IWireMockServer with reusing inside public (MappingMatcherResult Match, MappingMatcherResult Partial) FindBestMatch(RequestMessage request)

@marspox commented on GitHub (Jul 12, 2022): I see, but after sending HttpRequest I still don't know which mapping has been applied to get response. I'm writing a tool which uses WireMock.Net with proxy recording. After sending a request, mapping is automatically created if missing, I would like to get mapping or its guid in order to cache new mappings. It would be great to have such metod in `public partial class WireMockServer : IWireMockServer` with reusing inside `public (MappingMatcherResult Match, MappingMatcherResult Partial) FindBestMatch(RequestMessage request)`
Author
Owner

@MychellSantos commented on GitHub (Jul 27, 2022):

I have the same difficulty, I wanted to compare the map described with the map that was actually registered to locate the error but nothing is possible.
I analyze the "LogEntries" but nothing.

@MychellSantos commented on GitHub (Jul 27, 2022): I have the same difficulty, I wanted to compare the map described with the map that was actually registered to locate the error but nothing is possible. I analyze the "LogEntries" but nothing.
Author
Owner

@StefH commented on GitHub (Aug 25, 2022):

@marspox & @MychellSantos

A possible solution would be that you can use response templating to return the GUID from the matched mapping as a header for example.

So

"Response" : {
  "Headers" : [
    "Matched-Mapping-Guid": "{{mapping.guid}}"
  ],
  "UseTransformer" : true
}

Would that be ok?

@StefH commented on GitHub (Aug 25, 2022): @marspox & @MychellSantos A possible solution would be that you can use response templating to return the GUID from the matched mapping as a header for example. So ``` json "Response" : { "Headers" : [ "Matched-Mapping-Guid": "{{mapping.guid}}" ], "UseTransformer" : true } ``` Would that be ok?
Author
Owner

@StefH commented on GitHub (Aug 25, 2022):

@marspox & @MychellSantos

A preview version 1.5.4-ci-16400 supports this. Can you please test?

(how to use preview : https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)

@StefH commented on GitHub (Aug 25, 2022): @marspox & @MychellSantos A preview version `1.5.4-ci-16400` supports this. Can you please test? (how to use preview : https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions)
Author
Owner

@marspox commented on GitHub (Aug 25, 2022):

Hi StefH,
thanks, for adding this feature

@marspox commented on GitHub (Aug 25, 2022): Hi StefH, thanks, for adding this feature
Author
Owner

@StefH commented on GitHub (Aug 27, 2022):

@MychellSantos
Did you also have time to review / test ?

@StefH commented on GitHub (Aug 27, 2022): @MychellSantos Did you also have time to review / test ?
Author
Owner

@StefH commented on GitHub (Sep 1, 2022):

@marspox and @MychellSantos
Did you also have time to review / test ?

@StefH commented on GitHub (Sep 1, 2022): @marspox and @MychellSantos Did you also have time to review / test ?
Author
Owner

@StefH commented on GitHub (Sep 3, 2022):

@marspox and @MychellSantos : The PR is merged to master, a new NuGet will be released soon.

@StefH commented on GitHub (Sep 3, 2022): @marspox and @MychellSantos : The PR is merged to master, a new NuGet will be released soon.
Author
Owner

@MychellSantos commented on GitHub (Oct 21, 2022):

I do not activate time to test, I will evaluate the next package...

@MychellSantos commented on GitHub (Oct 21, 2022): I do not activate time to test, I will evaluate the next package...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#424