WireMock-Net / WireMock.Net

WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
Apache License 2.0
1.35k stars 197 forks source link

Proxying always goes to the root #1073

Closed JorisVanEijden closed 4 months ago

JorisVanEijden commented 4 months ago

Describe the bug

ProxyAndRecordSettings.Url = "https://www.example.com/some/sub/paths"

A request for "/someurl" is proxied to "https://www.example.com/someurl"

Expected behavior:

A request for "/someurl" is proxied to "https://www.example.com/some/sub/paths/someurl"

Other related info

The path to proxy to is determined by var proxyUriWithRequestPathAndQuery = new Uri(proxyUri, requestUri.PathAndQuery); Since requestUri.PathAndQuery will always start with a slash, the created uri will always only take the root of the proxyUri and ignore the sub paths.

*edit: A workaround:

ReplaceSettings = new ProxyUrlReplaceSettings
{
  OldValue = "example.com/",
  NewValue = "example.com/some/sub/paths/",
}
StefH commented 4 months ago

Hi @JorisVanEijden

The ProxyUrlReplaceSettings are indeed the correct way to implement your requirements.

See also this unit-test: https://github.com/WireMock-Net/WireMock.Net/blob/master/test/WireMock.Net.Tests/WireMockServer.Proxy.cs#L574

See also these issues and PR's