What's the intended behavior when combining recording proxy with watched mapping folder? #118

Closed
opened 2025-12-29 08:22:31 +01:00 by adam · 11 comments
Owner

Originally created by @DavidKorn on GitHub (Jul 4, 2018).

If I set up a proxy and also the ReadStaticFiles and WatchStaticFiles, and I make the same call twice, should I expect to hit the proxied endpoint the first time, record the mapping, and then use the mapping the second time? I was playing around with this a bit, and it seemed like sometimes this is what would happen, and other times it would continue to hit the real endpoint. I am probably doing something to on my side to exacerbate the issue, but I wanted to understand what I should be expecting.

Originally created by @DavidKorn on GitHub (Jul 4, 2018). If I set up a proxy and also the ReadStaticFiles and WatchStaticFiles, and I make the same call twice, should I expect to hit the proxied endpoint the first time, record the mapping, and then use the mapping the second time? I was playing around with this a bit, and it seemed like sometimes this is what would happen, and other times it would continue to hit the real endpoint. I am probably doing something to on my side to exacerbate the issue, but I wanted to understand what I should be expecting.
adam added the question label 2025-12-29 08:22:31 +01:00
adam closed this issue 2025-12-29 08:22:31 +01:00
Author
Owner

@StefH commented on GitHub (Jul 4, 2018):

Did you follow this link? https://github.com/WireMock-Net/WireMock.Net/wiki/Proxying

Your issue is probably related that the proxy en the real mapping get the same priority. That would explain your behaviour.

However, if you apply the correct priority, it should work as intended.

@StefH commented on GitHub (Jul 4, 2018): Did you follow this link? https://github.com/WireMock-Net/WireMock.Net/wiki/Proxying Your issue is probably related that the proxy en the real mapping get the same priority. That would explain your behaviour. However, if you apply the correct priority, it should work as intended.
Author
Owner

@DavidKorn commented on GitHub (Jul 5, 2018):

Ah makes sense. I'm just using the ProxyAndRecordSettings of the FluentMockServerSettings to establish a proxy URL when I start the server. I'm not seeing how to establish a priority for the proxy use that way.
Maybe both the proxy and the generated mappings are getting defaulted to zero and thus contending?
My assumption was that the proxy would be used as a fallback behavior for when I don't have a mapping, but that any mapping would take precedence over that fallback.

@DavidKorn commented on GitHub (Jul 5, 2018): Ah makes sense. I'm just using the ProxyAndRecordSettings of the FluentMockServerSettings to establish a proxy URL when I start the server. I'm not seeing how to establish a priority for the proxy use that way. Maybe both the proxy and the generated mappings are getting defaulted to zero and thus contending? My assumption was that the proxy would be used as a fallback behavior for when I don't have a mapping, but that any mapping would take precedence over that fallback.
Author
Owner

@StefH commented on GitHub (Jul 5, 2018):

Priority is defaulted to 0 indeed. You can manually change this in the mapping file.

If you want a sort of fall back scenario, see the bottom example on that wiki link I copied in my previous comment.

@StefH commented on GitHub (Jul 5, 2018): Priority is defaulted to 0 indeed. You can manually change this in the mapping file. If you want a sort of fall back scenario, see the bottom example on that wiki link I copied in my previous comment.
Author
Owner

@DavidKorn commented on GitHub (Jul 10, 2018):

Thanks, I'll play around some more as time allows. I think what I wanted is for the ProxyAndRecordSettings to allow me to set a lower priority when I establish the proxy there. But maybe I can do it with a fallback mapping like your example, as long as it still triggers the mapping recording.

@DavidKorn commented on GitHub (Jul 10, 2018): Thanks, I'll play around some more as time allows. I think what I wanted is for the ProxyAndRecordSettings to allow me to set a lower priority when I establish the proxy there. But maybe I can do it with a fallback mapping like your example, as long as it still triggers the mapping recording.
Author
Owner

@StefH commented on GitHub (Jul 10, 2018):

I just realised that I need to explain more on proxying functionality. Because there are 2 ways to proxy.

  1. Full proxy mode : Wiremock will only record requests and responses. This is useful if you want to record all traffic from a web app to a backend. See this code example https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs

  2. Proxy per defined mapping. This is described in the wiki. In this case you need to use priority to make a difference. I will think if defining an extra setting will automatically lower the prio from a proxied mapping.

Next week I will update the wiki with some details to make it more clear.

@StefH commented on GitHub (Jul 10, 2018): I just realised that I need to explain more on proxying functionality. Because there are 2 ways to proxy. 1. Full proxy mode : Wiremock will only record requests and responses. This is useful if you want to record all traffic from a web app to a backend. See this code example https://github.com/WireMock-Net/WireMock.Net/blob/master/examples/WireMock.Net.Console.Proxy.NETCoreApp2/Program.cs 2. Proxy per defined mapping. This is described in the wiki. In this case you need to use priority to make a difference. I will think if defining an extra setting will automatically lower the prio from a proxied mapping. Next week I will update the wiki with some details to make it more clear.
Author
Owner

@DavidKorn commented on GitHub (Jul 10, 2018):

Thanks @StefH . The use case I was trying to support is this: Our QA thinks we have all the needed mappings in place to mock a 3rd party API so we can do reliable tests of our code without actually hitting the 3rd party API. But if our client code generates a request not covered by the existing mappings, we'd like to fallback to the proxy record behavior and pass through to the real 3rd party API so we can easily capture that request in a new mapping file. We'll then have to clean it up as usual and fix the response, but this seemed like a convenient workflow.

@DavidKorn commented on GitHub (Jul 10, 2018): Thanks @StefH . The use case I was trying to support is this: Our QA thinks we have all the needed mappings in place to mock a 3rd party API so we can do reliable tests of our code without actually hitting the 3rd party API. But if our client code generates a request not covered by the existing mappings, we'd like to fallback to the proxy record behavior and pass through to the real 3rd party API so we can easily capture that request in a new mapping file. We'll then have to clean it up as usual and fix the response, but this seemed like a convenient workflow.
Author
Owner

@StefH commented on GitHub (Apr 5, 2019):

Can I close this question?

@StefH commented on GitHub (Apr 5, 2019): Can I close this question?
Author
Owner

@awcoats commented on GitHub (Mar 11, 2020):

I am having the same problem. I am able to 'record' without a problem. My problem is 'playing' back to the results.

For my example, I'm using http://example.mocklab.io/recordables/123

using System;
using WireMock.Server;
using WireMock.Settings;

namespace wiremockdemo1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var settings = new WireMockServerSettings
            {

                Urls = new[] { "https://localhost:9095/" },
                StartAdminInterface = true,
                ReadStaticMappings = true,
                AllowPartialMapping = true,
                WatchStaticMappings = true,
                ProxyAndRecordSettings = new ProxyAndRecordSettings
                {
                    Url = "http://example.mocklab.io",
                    SaveMapping = true,
                    SaveMappingToFile = true,
                    SaveMappingForStatusCodePattern = "2xx",
                    BlackListedHeaders = new[] { "dnt", "Content-Length" }
                }
            };
       
            var server = WireMockServer.Start(settings);
           
            Console.WriteLine("Press any key to stop the server");
            Console.ReadKey();
            server.Stop();
        }
    }
}

How do I configure to try and match with a recorded file and return that?

@awcoats commented on GitHub (Mar 11, 2020): I am having the same problem. I am able to 'record' without a problem. My problem is 'playing' back to the results. For my example, I'm using http://example.mocklab.io/recordables/123 ``` c# using System; using WireMock.Server; using WireMock.Settings; namespace wiremockdemo1 { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); var settings = new WireMockServerSettings { Urls = new[] { "https://localhost:9095/" }, StartAdminInterface = true, ReadStaticMappings = true, AllowPartialMapping = true, WatchStaticMappings = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://example.mocklab.io", SaveMapping = true, SaveMappingToFile = true, SaveMappingForStatusCodePattern = "2xx", BlackListedHeaders = new[] { "dnt", "Content-Length" } } }; var server = WireMockServer.Start(settings); Console.WriteLine("Press any key to stop the server"); Console.ReadKey(); server.Stop(); } } } ``` How do I configure to try and match with a recorded file and return that?
Author
Owner

@StefH commented on GitHub (Mar 11, 2020):

When 'playing' back, you just need to start WireMock in a different way, like:

var settings = new WireMockServerSettings
            {
                Urls = new[] { "https://localhost:9095/" },
                StartAdminInterface = true,
                ReadStaticMappings = true,
                AllowPartialMapping = true,
                WatchStaticMappings = true
            };

Also see this example project : https://github.com/richie676/wiremock

@StefH commented on GitHub (Mar 11, 2020): When 'playing' back, you just need to start WireMock in a different way, like: ``` c# var settings = new WireMockServerSettings { Urls = new[] { "https://localhost:9095/" }, StartAdminInterface = true, ReadStaticMappings = true, AllowPartialMapping = true, WatchStaticMappings = true }; ``` Also see this example project : https://github.com/richie676/wiremock
Author
Owner

@awcoats commented on GitHub (Mar 11, 2020):

That example worked for me. Thank you for quick response.

@awcoats commented on GitHub (Mar 11, 2020): That example worked for me. Thank you for quick response.
Author
Owner

@StefH commented on GitHub (Mar 11, 2020):

Closing...

@StefH commented on GitHub (Mar 11, 2020): Closing...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#118