mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 22:30:41 +01:00
When respond with proxy requestMessage.Url is used, not AbsoluteUrl #268
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @adatanasov on GitHub (Apr 28, 2020).
Hello,
I have the following working local setup in IIS:
website - wwwdev.company.com
web application - wwwdev.company.com/account
API - wwwdev.company.com/account/api
The web application calls the API with relative URL "/api/...".
I want to add tests for the web app which should call a mocked API and return the responses I want. All unmatched requests should be proxied to the 'real' API.
So, I create a new website, web app and API in IIS:
website - wwwmock.company.com
web application - wwwmock.company.com/account
API - wwwmock.company.com/account/api
For the mocked API I host a WireMock service on .NET Core 2.1, similar to the example 'WireMock.Net.WebApplication.NETCore2'.
This is the part where I setup the server:
So, I want when I call GET https://wwwmock.company.com/account/api/ping to get the response from the mock API. This works.
I also want when I call GET https://wwwmock.company.com/account/api/v2/environments/current this to be redirected to https://wwwdev.company.com/account/api/v2/environments/current, but it gets redirected to https://wwwdev.company.com/v2/environments/current - without the '/account/api' part.
This is logged for the request:
"Url": "https://wwwmock.company.com/v2/environments/current",
"AbsoluteUrl": "https://wwwmock.company.com/account/api/v2/environments/current",
I think this is because of this part of the code in Response.cs
So the code gets the PathAndQuery from Url, which is "/v2/environments/current" and the baseUrl from ProxyUrl which is "https://wwwdev.company.com".
My question is can I do something, so without changing the IIS setup I get the desired result - https://wwwmock.company.com/account/api/v2/environments/current to be redirected to https://wwwdev.company.com/account/api/v2/environments/current?
Let me know if I can provide more info.
@StefH commented on GitHub (Apr 28, 2020):
I would expect that using this code:
Any any request, like
https://wwwmock.company.com/anything/other/a/b/cWould call the proxy as:
https://wwwdev.company.com/anything/other/a/b/c?
@adatanasov commented on GitHub (Apr 29, 2020):
Thank you for the quick response!
I've tried that, but it's the same. This is info from the logger:
I believe it's because my WireMock service is hosted under '/account/api' and that part is omitted later from the Url.
@StefH commented on GitHub (Apr 29, 2020):
Just an analyze how the code currently works.
The setup is like:
Post request to

http://{{wm_hostname}}/postPost request to

http://{{wm_hostname}}/post/x/y/zPost request to

http://{{wm_hostname}}/a/b/cThe current logic from WireMock is that only the baseUrl from the ProxyUrl is used, so specifying "http://postman-echo.com/post" or in your case "https://wwwdev.company.com/account/api" does not work.
However I think you are right, and that there is actually wrong logic in WireMock.
So for option 3, the value from
proxyUriWithRequestPathAndQueryshould be set to "http://postman-echo.com/post/a/b/c".What do you think?
@adatanasov commented on GitHub (Apr 29, 2020):
Yep, this should solve my issue.
Also, it shouldn't break any existing apps/logic as you can set a base URL if you need to.
@StefH commented on GitHub (Apr 29, 2020):
Yes it should be backwards compatible.
Proposal:
proxyUrl =
http://postman-echo.com/post, request =http://{{wm_hostname}}/post==> proxyUriWithRequestPathAndQuery =http://postman-echo.com/postproxyUrl =
http://postman-echo.com/post, request =http://{{wm_hostname}}/post/x/y/z==> proxyUriWithRequestPathAndQuery =http://postman-echo.com/post/x/y/zproxyUrl =
http://postman-echo.com, request =http://{{wm_hostname}}/post/x/y/z==> proxyUriWithRequestPathAndQuery =http://postman-echo.com/post/x/y/zproxyUrl =
http://postman-echo.com/other, request =http://{{wm_hostname}}/post/x/y/z==> proxyUriWithRequestPathAndQuery =http://postman-echo.com/other/post/x/y/zCorrect?
@adatanasov commented on GitHub (Apr 29, 2020):
I agree.
@StefH commented on GitHub (Apr 29, 2020):
Can you try MyGet version : WireMock.Net.1.2.6-ci-13251.nupkg
@StefH commented on GitHub (Apr 29, 2020):
https://github.com/WireMock-Net/WireMock.Net/pull/461
@adatanasov commented on GitHub (Apr 29, 2020):
It works as agreed.
Thanks again for the quick reaction :)
@StefH commented on GitHub (Apr 29, 2020):
I'll make a new official release tomorrow.