Partial proxy stub mapping #479

Closed
opened 2025-12-29 15:24:46 +01:00 by adam · 4 comments
Owner

Originally created by @ThokerWD on GitHub (Jan 11, 2023).

Is it possible to define a proxy stub mapping similar to the following one ?

{
    "request": {
        "method": "GET",
        "urlPattern": "/other/service/.*"
    },
    "response": {
        "proxyBaseUrl": "http://otherhost.com/approot"
    }
}

So that requests matching this template get proxied to "http://otherhost.com" and other responses get matched by my local logic ?

Originally created by @ThokerWD on GitHub (Jan 11, 2023). Is it possible to define a proxy stub mapping similar to the following one ? ```json { "request": { "method": "GET", "urlPattern": "/other/service/.*" }, "response": { "proxyBaseUrl": "http://otherhost.com/approot" } } ``` So that requests matching this template get proxied to "http://otherhost.com" and other responses get matched by my local logic ?
adam added the question label 2025-12-29 15:24:46 +01:00
adam closed this issue 2025-12-29 15:24:46 +01:00
Author
Owner

@StefH commented on GitHub (Jan 11, 2023):

You need two mappings.

This example should work (in case your real host is named "realhost.com")

[
{
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/other/service"
          }
        ]
      },
      "Methods": [
        "get"
      ]
    },
    "Response": {
      "ProxyUrl": "http://otherhost.com"
    }
},
{
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/other/abc"
          }
        ]
      },
      "Methods": [
        "get"
      ]
    },
    "Response": {
      "ProxyUrl": "http://realhost.com"
    }
}
]
@StefH commented on GitHub (Jan 11, 2023): You need two mappings. This example should work (in case your real host is named "realhost.com") ``` json [ { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/other/service" } ] }, "Methods": [ "get" ] }, "Response": { "ProxyUrl": "http://otherhost.com" } }, { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/other/abc" } ] }, "Methods": [ "get" ] }, "Response": { "ProxyUrl": "http://realhost.com" } } ] ```
Author
Owner

@ThokerWD commented on GitHub (Jan 12, 2023):

Thanks for the quick reply @StefH . Unfortunately I can't make this work together with client certificate authentication for a https server.

When this is configured under ProxyAndRecordSettings, then the authentication works fine, but then all requests get proxied to the configured URL.

Is there a possibility to configure a ClientCertificate together with a ProxyUrl ?

Example:

[
{
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/other/service"
          }
        ]
      },
      "Methods": [
        "get"
      ]
    },
    "Response": {
      "ProxyUrl": "https://otherhost.com",
      "clientX509Certificate2ThumbprintOrSubjectName": "thumbprintorsubjectname"

    }
},
{
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "WildcardMatcher",
            "Pattern": "/other/abc"
          }
        ]
      },
      "Methods": [
        "get"
      ]
    },
    "Response": {
      "body": "local response"
    }
}
]
@ThokerWD commented on GitHub (Jan 12, 2023): Thanks for the quick reply @StefH . Unfortunately I can't make this work together with client certificate authentication for a https server. When this is configured under `ProxyAndRecordSettings`, then the authentication works fine, but then all requests get proxied to the configured URL. Is there a possibility to configure a ClientCertificate together with a ProxyUrl ? Example: ```json [ { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/other/service" } ] }, "Methods": [ "get" ] }, "Response": { "ProxyUrl": "https://otherhost.com", "clientX509Certificate2ThumbprintOrSubjectName": "thumbprintorsubjectname" } }, { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/other/abc" } ] }, "Methods": [ "get" ] }, "Response": { "body": "local response" } } ] ```
Author
Owner

@StefH commented on GitHub (Jan 12, 2023):

In your case, do not define a global proxy, but only in the mappings.

Like here:
https://github.com/WireMock-Net/WireMock.Net/wiki/Proxying#proxyintercept

@StefH commented on GitHub (Jan 12, 2023): In your case, do not define a global proxy, but only in the mappings. Like here: https://github.com/WireMock-Net/WireMock.Net/wiki/Proxying#proxyintercept
Author
Owner

@ThokerWD commented on GitHub (Jan 12, 2023):

Thank you, this way I can also specify a certificate for this proxy. I think this is currently only supported in code and not in json though.

// Low priority catch-all proxies to otherhost.com by default
server
  .Given(
    Request.Create()
      .WithPath("/*")
  )
  .AtPriority(10)
  .RespondWith(
    Response.Create()
      .WithProxy("https://otherhost.com","thumbprint_or_subject") // this is what I needed
  );
@ThokerWD commented on GitHub (Jan 12, 2023): Thank you, this way I can also specify a certificate for this proxy. I think this is currently only supported in code and not in json though. ``` // Low priority catch-all proxies to otherhost.com by default server .Given( Request.Create() .WithPath("/*") ) .AtPriority(10) .RespondWith( Response.Create() .WithProxy("https://otherhost.com","thumbprint_or_subject") // this is what I needed ); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#479