Proxy with Transform #163

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

Originally created by @gregoks on GitHub (Feb 18, 2019).

Hello,

I saw in the wiremock that its possible to use Proxy with Transform - http://wiremock.org/docs/response-templating/

wm.stubFor(get(urlPathEqualTo("/templated"))
  .willReturn(aResponse()
      .proxiedFrom("{{request.headers.X-WM-Proxy-Url}}")
      .withTransformers("response-template")));

I wasnt able to do that in WireMock.Net, it just sets UseTransformer=False. is it possible? In your code I see that perhaps its not since in proxying you do not use Transformer:

 if (response.ProxyUrl == null || response._httpClientForProxy == null)
        return !response.UseTransformer ? response.ResponseMessage : ResponseMessageTransformer.Transform(requestMessage, response.ResponseMessage);
      Uri uri1 = new Uri(requestMessage.Url);
      Uri uri2 = new Uri(new Uri(response.ProxyUrl), uri1.PathAndQuery);
      return await HttpClientHelper.SendAsync(response._httpClientForProxy, requestMessage, uri2.AbsoluteUri);

Thanks!

Greg

Originally created by @gregoks on GitHub (Feb 18, 2019). Hello, I saw in the wiremock that its possible to use Proxy with Transform - http://wiremock.org/docs/response-templating/ ``` wm.stubFor(get(urlPathEqualTo("/templated")) .willReturn(aResponse() .proxiedFrom("{{request.headers.X-WM-Proxy-Url}}") .withTransformers("response-template"))); ``` I wasnt able to do that in WireMock.Net, it just sets UseTransformer=False. is it possible? In your code I see that perhaps its not since in proxying you do not use Transformer: ``` if (response.ProxyUrl == null || response._httpClientForProxy == null) return !response.UseTransformer ? response.ResponseMessage : ResponseMessageTransformer.Transform(requestMessage, response.ResponseMessage); Uri uri1 = new Uri(requestMessage.Url); Uri uri2 = new Uri(new Uri(response.ProxyUrl), uri1.PathAndQuery); return await HttpClientHelper.SendAsync(response._httpClientForProxy, requestMessage, uri2.AbsoluteUri); ``` Thanks! Greg
adam closed this issue 2025-12-29 08:23:14 +01:00
Author
Owner

@StefH commented on GitHub (Feb 18, 2019):

I guess it's not supported, however what would be the use-case for this feature?

@StefH commented on GitHub (Feb 18, 2019): I guess it's not supported, however what would be the use-case for this feature?
Author
Owner

@gregoks commented on GitHub (Feb 18, 2019):

I'm trying to make a proxy to another server.
My use case is this:

Service A calls Service B.
Service B url is configured in Service A Web.Config.

I'm using WireMock to mock Service B so I'm putting in Web.Config of Service A the address of my WireMock server instead of the actual Service B URL.

I want to have something similar to the priorities example that you have in the wiki, so specific mappings which will be done from my automation solution (which tests Service A) will go to the WireMocked service (instead of Service B) but I want all other calls which are done by real service will go to the actual Service B url and I want all the request parameters to be passed as well, including headers, body, query string etc.

I hope that's clear, if not then I'll try to explain better..

@gregoks commented on GitHub (Feb 18, 2019): I'm trying to make a proxy to another server. My use case is this: Service A calls Service B. Service B url is configured in Service A Web.Config. I'm using WireMock to mock Service B so I'm putting in Web.Config of Service A the address of my WireMock server instead of the actual Service B URL. I want to have something similar to the priorities example that you have in the wiki, so specific mappings which will be done from my automation solution (which tests Service A) will go to the WireMocked service (instead of Service B) but I want all other calls which are done by real service will go to the actual Service B url and I want all the request parameters to be passed as well, including headers, body, query string etc. I hope that's clear, if not then I'll try to explain better..
Author
Owner

@StefH commented on GitHub (Feb 18, 2019):

Can't you just use priority and add a specific automation only header match?

So:
Service A calls Service B.
WireMock is configured in Service A Web.Config and will proxy to service B

Automation calls Service A and with a extra header like "Automation" = "yes"
WireMock will respond with mocks when header like "Automation" = "yes" is found
Else WireMock will proxy to real Service.

Could this work?

@StefH commented on GitHub (Feb 18, 2019): Can't you just use priority and add a specific automation only header match? So: Service A calls Service B. WireMock is configured in Service A Web.Config and will proxy to service B Automation calls Service A and with a extra header like "Automation" = "yes" WireMock will respond with mocks when header like "Automation" = "yes" is found Else WireMock will proxy to real Service. Could this work?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#163