Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy with Transform #252

Closed
gregoks opened this issue Feb 18, 2019 · 3 comments
Closed

Proxy with Transform #252

gregoks opened this issue Feb 18, 2019 · 3 comments

Comments

@gregoks
Copy link

gregoks commented Feb 18, 2019

Hello,

I saw in the wiremock that its possible to use Proxy with Transform - http:https://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

@StefH
Copy link
Collaborator

StefH commented Feb 18, 2019

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

@gregoks
Copy link
Author

gregoks commented 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..

@StefH
Copy link
Collaborator

StefH commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants