ProxyURL path configuration #717

Closed
opened 2025-12-29 08:32:53 +01:00 by adam · 13 comments
Owner

Originally created by @tomas-pinto on GitHub (Sep 24, 2025).

Originally assigned to: @StefH on GitHub.

Is it possible to add transformers to url path logic?

In case the request is of the form: http://host1/a/b/c, I want to be able to proxy to http://host2/c/d.

Originally created by @tomas-pinto on GitHub (Sep 24, 2025). Originally assigned to: @StefH on GitHub. Is it possible to add transformers to url path logic? In case the request is of the form: http://host1/a/b/c, I want to be able to proxy to http://host2/c/d.
adam added the feature label 2025-12-29 08:32:53 +01:00
adam closed this issue 2025-12-29 08:32:53 +01:00
Author
Owner

@StefH commented on GitHub (Sep 28, 2025):

@tomas-pinto

Current you can indeed only replace source path with a hard-coded new path using:

/// <summary>
/// Defines an old path param and a new path param to be replaced when proxying.
/// </summary>
public class ProxyUrlReplaceSettings
{
    /// <summary>
    /// The old path value to be replaced by the new path value
    /// </summary>
    public string OldValue { get; set; } = null!;

    /// <summary>
    /// The new path value to replace the old value with
    /// </summary>
    public string NewValue { get; set; } = null!;

    /// <summary>
    /// Defines if the case should be ignored when replacing.
    /// </summary>
    public bool IgnoreCase { get; set; }
}

I think it's possible to add logic so that NewValue will also be handled as a Handlebars template, which means you should be able to do any transform you like.

Is this a solution?

@StefH commented on GitHub (Sep 28, 2025): @tomas-pinto Current you can indeed only replace source path with a hard-coded new path using: ``` c# /// <summary> /// Defines an old path param and a new path param to be replaced when proxying. /// </summary> public class ProxyUrlReplaceSettings { /// <summary> /// The old path value to be replaced by the new path value /// </summary> public string OldValue { get; set; } = null!; /// <summary> /// The new path value to replace the old value with /// </summary> public string NewValue { get; set; } = null!; /// <summary> /// Defines if the case should be ignored when replacing. /// </summary> public bool IgnoreCase { get; set; } } ``` I think it's possible to add logic so that `NewValue` will also be handled as a Handlebars template, which means you should be able to do any transform you like. Is this a solution?
Author
Owner

@StefH commented on GitHub (Sep 28, 2025):

https://github.com/wiremock/WireMock.Net/pull/1361

@StefH commented on GitHub (Sep 28, 2025): https://github.com/wiremock/WireMock.Net/pull/1361
Author
Owner

@tomas-pinto commented on GitHub (Sep 30, 2025):

Thank you very much @StefH! That seems to be what I needed.
Could you please update wiremock.net-windows docker image for me to test?

@tomas-pinto commented on GitHub (Sep 30, 2025): Thank you very much @StefH! That seems to be what I needed. Could you please update wiremock.net-windows docker image for me to test?
Author
Owner

@StefH commented on GitHub (Sep 30, 2025):

@tomas-pinto
mmm,

I doubt if you can configure this new logic in docker?

@StefH commented on GitHub (Sep 30, 2025): @tomas-pinto mmm, I doubt if you can configure this new logic in docker?
Author
Owner

@StefH commented on GitHub (Sep 30, 2025):

@tomas-pinto
I just checked, it's not yet possible to configure this using mapping json. I need to make a fix.

@StefH commented on GitHub (Sep 30, 2025): @tomas-pinto I just checked, it's not yet possible to configure this using mapping json. I need to make a fix.
Author
Owner

@StefH commented on GitHub (Sep 30, 2025):

The json model will look like:

public class ProxyUrlReplaceSettingsModel
{
    /// <summary>
    /// The old path value to be replaced by the new path value
    /// </summary>
    public string OldValue { get; set; } = null!;

    /// <summary>
    /// The new path value to replace the old value with
    /// </summary>
    public string NewValue { get; set; } = null!;

    /// <summary>
    /// Defines if the case should be ignored when replacing.
    /// </summary>
    public bool IgnoreCase { get; set; }

    /// <summary>
    /// Holds the transformation template.
    /// </summary>
    public string? TransformTemplate { get; set; }

    /// <summary>
    /// The transformer type.
    /// </summary>
    public TransformerType TransformerType { get; set; } = TransformerType.Handlebars;
}
@StefH commented on GitHub (Sep 30, 2025): The json model will look like: ``` c# public class ProxyUrlReplaceSettingsModel { /// <summary> /// The old path value to be replaced by the new path value /// </summary> public string OldValue { get; set; } = null!; /// <summary> /// The new path value to replace the old value with /// </summary> public string NewValue { get; set; } = null!; /// <summary> /// Defines if the case should be ignored when replacing. /// </summary> public bool IgnoreCase { get; set; } /// <summary> /// Holds the transformation template. /// </summary> public string? TransformTemplate { get; set; } /// <summary> /// The transformer type. /// </summary> public TransformerType TransformerType { get; set; } = TransformerType.Handlebars; } ```
Author
Owner

@StefH commented on GitHub (Sep 30, 2025):

https://github.com/wiremock/WireMock.Net/pull/1362

@StefH commented on GitHub (Sep 30, 2025): https://github.com/wiremock/WireMock.Net/pull/1362
Author
Owner

@tomas-pinto commented on GitHub (Oct 1, 2025):

Hello @StefH, I tested with image "sheyenrath/wiremock.net-windows:1.13.0" and when I give only the TransformerTemplate parameter in the mapping I get a 500 saying:

{
    "Status": "Value cannot be null. (Parameter 'oldValue')"
}

Mapping that was posted:

{
    "Guid": "f1c4d6b0-4125-4726-a882-a11050a68b28",
    "UpdatedAt": "2025-09-30T15:51:33.0785915Z",
    "Request": {
      "Path": {
        "Matchers": [
          {
            "Name": "RegexMatcher",
            "Pattern": "/(.*?)"
          }
        ]
      },
      "Methods": [
        "POST"
      ]
    },
    "Response": {
      "ProxyUrl": "http://abc",
      "ProxyUrlReplaceSettings": {
        "TransformTemplate": "{{this}}-transformed"
      }
    }
}

Additionally, if I do GET mappings "TransformTemplate" is not being parsed:

{
        "Guid": "f1c4d6b0-4125-4726-a882-a11050a68b28",
        "UpdatedAt": "2025-10-01T08:25:47.769994Z",
        "Request": {
            "Path": {
                "Matchers": [
                    {
                        "Name": "RegexMatcher",
                        "Pattern": "/(.*?)",
                        "IgnoreCase": false
                    }
                ]
            },
            "Methods": [
                "POST"
            ]
        },
        "Response": {
            "ProxyUrl": "http://abc",
            "ProxyUrlReplaceSettings": {
                "IgnoreCase": false
            }
        }
}
@tomas-pinto commented on GitHub (Oct 1, 2025): Hello @StefH, I tested with image "sheyenrath/wiremock.net-windows:1.13.0" and when I give only the TransformerTemplate parameter in the mapping I get a 500 saying: ``` { "Status": "Value cannot be null. (Parameter 'oldValue')" } ``` Mapping that was posted: ``` { "Guid": "f1c4d6b0-4125-4726-a882-a11050a68b28", "UpdatedAt": "2025-09-30T15:51:33.0785915Z", "Request": { "Path": { "Matchers": [ { "Name": "RegexMatcher", "Pattern": "/(.*?)" } ] }, "Methods": [ "POST" ] }, "Response": { "ProxyUrl": "http://abc", "ProxyUrlReplaceSettings": { "TransformTemplate": "{{this}}-transformed" } } } ``` Additionally, if I do GET mappings "TransformTemplate" is not being parsed: ``` { "Guid": "f1c4d6b0-4125-4726-a882-a11050a68b28", "UpdatedAt": "2025-10-01T08:25:47.769994Z", "Request": { "Path": { "Matchers": [ { "Name": "RegexMatcher", "Pattern": "/(.*?)", "IgnoreCase": false } ] }, "Methods": [ "POST" ] }, "Response": { "ProxyUrl": "http://abc", "ProxyUrlReplaceSettings": { "IgnoreCase": false } } } ```
Author
Owner

@StefH commented on GitHub (Oct 1, 2025):

  • 500 error should not happen ; i will check that
  • TransformTemplate is not yet parsed, I need to add some more logic and create a new docker
@StefH commented on GitHub (Oct 1, 2025): - 500 error should not happen ; i will check that - TransformTemplate is not yet parsed, I need to add some more logic and create a new docker
Author
Owner

@StefH commented on GitHub (Oct 3, 2025):

@tomas-pinto can you try docker version 1.14.0-preview-01?

@StefH commented on GitHub (Oct 3, 2025): @tomas-pinto can you try docker version `1.14.0-preview-01`?
Author
Owner

@StefH commented on GitHub (Oct 4, 2025):

@tomas-pinto were you able test this version?

@StefH commented on GitHub (Oct 4, 2025): @tomas-pinto were you able test this version?
Author
Owner

@tomas-pinto commented on GitHub (Oct 6, 2025):

Yes, this version doesn't show the previous mentioned error and I've been able to do the reverse proxying I needed! Thank you very much!

@tomas-pinto commented on GitHub (Oct 6, 2025): Yes, this version doesn't show the previous mentioned error and I've been able to do the reverse proxying I needed! Thank you very much!
Author
Owner

@StefH commented on GitHub (Oct 6, 2025):

Thanks for verification.

@StefH commented on GitHub (Oct 6, 2025): Thanks for verification.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#717