Ignore OPTIONS request when using proxyandrecord #498

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

Originally created by @bhargavjulaganti on GitHub (Mar 7, 2023).

Originally assigned to: @StefH on GitHub.

I am using wire mock as a standalone server, to record my web requests. Currently it is recording OPTIONS request as well when saving the mapping to the file .

Is there an extension I could use, so it does not save OPTIONS request, like how we are excluding specific headers not to save in mappings file

var url = "http://localhost:9095";

Console.WriteLine($"WireMock Recording on {url}");

var settings = new WireMockServerSettings
{
    Urls = new[] { url },
    StartAdminInterface = true,
    ProxyAndRecordSettings = new ProxyAndRecordSettings
    {
        Url = "random url",
        SaveMapping = true,
        SaveMappingToFile = true,
        SaveMappingForStatusCodePattern = "2xx,4xx",
        ExcludedHeaders = new[]
        {
            "Postman-Token",
            "Host",
            "Authorization",
            "User-Agent",
            "Cache-Control"
        }
    }
};

var server = WireMockServer.Start(settings);
Originally created by @bhargavjulaganti on GitHub (Mar 7, 2023). Originally assigned to: @StefH on GitHub. I am using wire mock as a standalone server, to record my web requests. Currently it is recording OPTIONS request as well when saving the mapping to the file . Is there an extension I could use, so it does not save OPTIONS request, like how we are excluding specific headers not to save in mappings file ```cs var url = "http://localhost:9095"; Console.WriteLine($"WireMock Recording on {url}"); var settings = new WireMockServerSettings { Urls = new[] { url }, StartAdminInterface = true, ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "random url", SaveMapping = true, SaveMappingToFile = true, SaveMappingForStatusCodePattern = "2xx,4xx", ExcludedHeaders = new[] { "Postman-Token", "Host", "Authorization", "User-Agent", "Cache-Control" } } }; var server = WireMockServer.Start(settings); ```
adam added the feature label 2025-12-29 15:25:18 +01:00
adam closed this issue 2025-12-29 15:25:19 +01:00
Author
Owner

@StefH commented on GitHub (Mar 8, 2023):

@bhargavjulaganti
This can be added.

I'll take a look.

@StefH commented on GitHub (Mar 8, 2023): @bhargavjulaganti This can be added. I'll take a look.
Author
Owner

@StefH commented on GitHub (Mar 8, 2023):

Can you try preview version (1.5.17-ci-17145) ?

https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions

@StefH commented on GitHub (Mar 8, 2023): Can you try preview version (1.5.17-ci-17145) ? https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions
Author
Owner

@bhargavjulaganti commented on GitHub (Mar 8, 2023):

I updated the version to 1.5.17-ci-17145 and tried it. I am still seeing OPTIONS file is getting created

image

image

@bhargavjulaganti commented on GitHub (Mar 8, 2023): I updated the version to `1.5.17-ci-17145` and tried it. I am still seeing OPTIONS file is getting created ![image](https://user-images.githubusercontent.com/11901773/223725408-7a9a6688-4dc9-49e5-8264-bc42e914dfcb.png) ![image](https://user-images.githubusercontent.com/11901773/223725489-c2764338-cb12-48fb-b480-5a2af175cb81.png)
Author
Owner

@StefH commented on GitHub (Mar 8, 2023):

Please try 17147

@StefH commented on GitHub (Mar 8, 2023): Please try 17147
Author
Owner

@bhargavjulaganti commented on GitHub (Mar 8, 2023):

still seeing the same issue. When I look at your change , I see you are looking for request matchers.

I do not have any request matchers in my code. I am just running wiremock as a standalone application

@bhargavjulaganti commented on GitHub (Mar 8, 2023): still seeing the same issue. When I look at your [change](https://github.com/WireMock-Net/WireMock.Net/blob/7312688eea4ae2eabf0f0c1465b7358fcf817126/src/WireMock.Net/Serialization/ProxyMappingConverter.cs#L48) , I see you are looking for request matchers. I do not have any request matchers in my code. I am just running wiremock as a standalone application
Author
Owner

@StefH commented on GitHub (Mar 8, 2023):

You are correct.

Actually a new setting like DoNotSaveMappingForHttpMethods should be added. Just like SaveMappingForStatusCodePattern.

@StefH commented on GitHub (Mar 8, 2023): You are correct. Actually a new setting like DoNotSaveMappingForHttpMethods should be added. Just like SaveMappingForStatusCodePattern.
Author
Owner

@StefH commented on GitHub (Mar 8, 2023):

@bhargavjulaganti
New code works like:

ProxyAndRecordSettings = new ProxyAndRecordSettings
            {
                Url = "http://www.google.com",
                SaveMapping = true,
                SaveMappingToFile = true,
                SaveMappingSettings = new ProxySaveMappingSettings
                {
                    StatusCodePattern = "2xx,4xx",
                    HttpMethods = new ProxySaveMappingSetting<string[]>(new string[] { "GET" }, MatchBehaviour.RejectOnMatch) // To make sure that we don't want this mapping
                }
            },

(new preview NuGet will be published within some minutes, just take the most recent version)

@StefH commented on GitHub (Mar 8, 2023): @bhargavjulaganti New code works like: ``` c# ProxyAndRecordSettings = new ProxyAndRecordSettings { Url = "http://www.google.com", SaveMapping = true, SaveMappingToFile = true, SaveMappingSettings = new ProxySaveMappingSettings { StatusCodePattern = "2xx,4xx", HttpMethods = new ProxySaveMappingSetting<string[]>(new string[] { "GET" }, MatchBehaviour.RejectOnMatch) // To make sure that we don't want this mapping } }, ``` (new preview NuGet will be published within some minutes, just take the most recent version)
Author
Owner

@bhargavjulaganti commented on GitHub (Mar 9, 2023):

That worked . Thanks for the quick update :)

image

@bhargavjulaganti commented on GitHub (Mar 9, 2023): That worked . Thanks for the quick update :) ![image](https://user-images.githubusercontent.com/11901773/224022689-6bcdbe86-0412-4d04-b471-decf64af02d7.png)
Author
Owner

@StefH commented on GitHub (Mar 9, 2023):

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

@StefH commented on GitHub (Mar 9, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/900
Author
Owner

@StefH commented on GitHub (Mar 9, 2023):

An official NuGet will be released in the next days.

@StefH commented on GitHub (Mar 9, 2023): An official NuGet will be released in the next days.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#498