Scenario with proxy not removing route prefix #553

Closed
opened 2025-12-29 08:30:03 +01:00 by adam · 7 comments
Owner

Originally created by @mark-hingston on GitHub (Dec 1, 2023).

Originally assigned to: @StefH on GitHub.

I'm using WireMock.Net.StandAlone 1.5.39 and have the following scenario:

[
  {
    "Scenario": "HyperPaySucceedOnThirdTryScenario",
    "SetStateTo": "SecondAttempt",
    "Priority": 1,
    "Request": {
      "Methods": ["GET", "POST"],
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/hyperpay/*",
            "IgnoreCase": false
          }
        ]
      }
    },
    "Response": {
      "StatusCode": 503,
      "Headers": {
        "X-PureTrace-Wiremock": "HyperPay 503 - Server Unavailable - Attempt 1"
      }
    }
  },
  {
    "Scenario": "HyperPaySucceedOnThirdTryScenario",
    "WhenStateIs": "SecondAttempt",
    "SetStateTo": "ThirdAttempt",
    "Priority": 1,
    "Request": {
      "Methods": [ "GET", "POST" ],
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/hyperpay/*",
            "IgnoreCase": false
          }
        ]
      }
    },
    "Response": {
      "StatusCode": 503,
      "Headers": {
        "X-PureTrace-Wiremock": "HyperPay 503 - Server Unavailable - Attempt 2"
      }
    }
  },
  {
    "Scenario": "HyperPaySucceedOnThirdTryScenario",
    "WhenStateIs": "ThirdAttempt",
    "Priority": 1,
    "Request": {
      "Methods": [ "GET", "POST" ],
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/hyperpay/*",
            "IgnoreCase": false
          }
        ]
      }
    },
    "Response": {
      "ProxyUrl": "https://eu-test.oppwa.com"
    }
  }
]

The issue I'm finding is that on the third request when proxying to the upstream it is including the route prefix in the path e.g.

https://eu-test.oppwa.com/hyperpay/v1/checkouts instead of https://eu-test.oppwa.com/v1/checkouts.

How can I remove the route prefix? Thanks

Originally created by @mark-hingston on GitHub (Dec 1, 2023). Originally assigned to: @StefH on GitHub. I'm using WireMock.Net.StandAlone 1.5.39 and have the following scenario: ```json [ { "Scenario": "HyperPaySucceedOnThirdTryScenario", "SetStateTo": "SecondAttempt", "Priority": 1, "Request": { "Methods": ["GET", "POST"], "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/hyperpay/*", "IgnoreCase": false } ] } }, "Response": { "StatusCode": 503, "Headers": { "X-PureTrace-Wiremock": "HyperPay 503 - Server Unavailable - Attempt 1" } } }, { "Scenario": "HyperPaySucceedOnThirdTryScenario", "WhenStateIs": "SecondAttempt", "SetStateTo": "ThirdAttempt", "Priority": 1, "Request": { "Methods": [ "GET", "POST" ], "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/hyperpay/*", "IgnoreCase": false } ] } }, "Response": { "StatusCode": 503, "Headers": { "X-PureTrace-Wiremock": "HyperPay 503 - Server Unavailable - Attempt 2" } } }, { "Scenario": "HyperPaySucceedOnThirdTryScenario", "WhenStateIs": "ThirdAttempt", "Priority": 1, "Request": { "Methods": [ "GET", "POST" ], "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/hyperpay/*", "IgnoreCase": false } ] } }, "Response": { "ProxyUrl": "https://eu-test.oppwa.com" } } ] ``` The issue I'm finding is that on the third request when proxying to the upstream it is including the route prefix in the path e.g. `https://eu-test.oppwa.com/hyperpay/v1/checkouts` instead of `https://eu-test.oppwa.com/v1/checkouts`. How can I remove the route prefix? Thanks
adam added the feature label 2025-12-29 08:30:03 +01:00
adam closed this issue 2025-12-29 08:30:03 +01:00
Author
Owner

@StefH commented on GitHub (Dec 3, 2023):

Currently it's not yet possible to define this per request.

But you can define it in the settings:
https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#proxyandrecordsettings

via ReplaceSettings

@StefH commented on GitHub (Dec 3, 2023): Currently it's not yet possible to define this per request. But you can define it in the settings: https://github.com/WireMock-Net/WireMock.Net/wiki/Settings#proxyandrecordsettings via ReplaceSettings
Author
Owner

@StefH commented on GitHub (Dec 3, 2023):

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

@StefH commented on GitHub (Dec 3, 2023): https://github.com/WireMock-Net/WireMock.Net/pull/1026
Author
Owner

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

@mark-hingston Did you have time to test this, or should I just merge this change?

@StefH commented on GitHub (Dec 8, 2023): @mark-hingston Did you have time to test this, or should I just merge this change?
Author
Owner

@mark-hingston commented on GitHub (Dec 9, 2023):

@StefH I haven't had the chance to test the changes in the PR, but it looks good to merge 👍

Thanks again.

@mark-hingston commented on GitHub (Dec 9, 2023): @StefH I haven't had the chance to test the changes in the PR, but it looks good to merge 👍 Thanks again.
Author
Owner

@StefH commented on GitHub (Dec 10, 2023):

PR is merged. A new NuGet will be released this week.

@StefH commented on GitHub (Dec 10, 2023): PR is merged. A new NuGet will be released this week.
Author
Owner

@mark-hingston commented on GitHub (Jan 15, 2024):

Hi @StefH

I'm sending the following mapping to the POST __admin/mappings endpoint:

[{
    "Scenario": "SucceedOnThirdAttemptScenario",
    "SetStateTo": "SecondAttempt",
    "Priority": 1,
    "Request": {
      "Methods": ["GET", "POST"],
      "Path": {
        "Matchers": [{
          "Name": "WildcardMatcher",
          "Pattern": "/google/*",
          "IgnoreCase": false
        }]
      }
    },
    "Response": {
      "StatusCode": 503
    }
  },
  {
    "Scenario": "SucceedOnThirdAttemptScenario",
    "WhenStateIs": "SecondAttempt",
    "SetStateTo": "ThirdAttempt",
    "Priority": 1,
    "Request": {
      "Methods": ["GET", "POST"],
      "Path": {
        "Matchers": [{
          "Name": "WildcardMatcher",
          "Pattern": "/google/*",
          "IgnoreCase": false
        }]
      }
    },
    "Response": {
      "StatusCode": 503
    }
  },
  {
    "Scenario": "SucceedOnThirdAttemptScenario",
    "WhenStateIs": "ThirdAttempt",
    "Priority": 1,
    "Request": {
      "Methods": ["GET", "POST"],
      "Path": {
        "Matchers": [{
          "Name": "WildcardMatcher",
          "Pattern": "/google/*",
          "IgnoreCase": false
        }]
      }
    },
    "Response": {
      "ProxyUrl": "https://google.com",
      "ProxyUrlReplaceSettings ": {
        "OldValue": "/google",
        "NewValue": "",
        "IgnoreCase": true
      }
    }
  }
]

When I try requesting <wiremockAddress>/google/search in my browser, on the third attempt it is proxying to: https://google.com/google/search. Am I missing something here?

Many thanks.

@mark-hingston commented on GitHub (Jan 15, 2024): Hi @StefH I'm sending the following mapping to the POST `__admin/mappings` endpoint: ```json [{ "Scenario": "SucceedOnThirdAttemptScenario", "SetStateTo": "SecondAttempt", "Priority": 1, "Request": { "Methods": ["GET", "POST"], "Path": { "Matchers": [{ "Name": "WildcardMatcher", "Pattern": "/google/*", "IgnoreCase": false }] } }, "Response": { "StatusCode": 503 } }, { "Scenario": "SucceedOnThirdAttemptScenario", "WhenStateIs": "SecondAttempt", "SetStateTo": "ThirdAttempt", "Priority": 1, "Request": { "Methods": ["GET", "POST"], "Path": { "Matchers": [{ "Name": "WildcardMatcher", "Pattern": "/google/*", "IgnoreCase": false }] } }, "Response": { "StatusCode": 503 } }, { "Scenario": "SucceedOnThirdAttemptScenario", "WhenStateIs": "ThirdAttempt", "Priority": 1, "Request": { "Methods": ["GET", "POST"], "Path": { "Matchers": [{ "Name": "WildcardMatcher", "Pattern": "/google/*", "IgnoreCase": false }] } }, "Response": { "ProxyUrl": "https://google.com", "ProxyUrlReplaceSettings ": { "OldValue": "/google", "NewValue": "", "IgnoreCase": true } } } ] ``` When I try requesting `<wiremockAddress>/google/search` in my browser, on the third attempt it is proxying to: `https://google.com/google/search`. Am I missing something here? Many thanks.
Author
Owner

@StefH commented on GitHub (Jan 23, 2024):

@mark-hingston
I cannot understand your issue here?

@StefH commented on GitHub (Jan 23, 2024): @mark-hingston I cannot understand your issue here?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#553