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

When using Proxying with the ResponseTemplateTransformer the setting proxyUrlPrefixToRemove is ignored #1783

Closed
andrena-eike-kohnert opened this issue Jan 25, 2022 · 8 comments

Comments

@andrena-eike-kohnert
Copy link

WireMock version: 2.32.0

How to reproduce:

Use the following mapping:

{
  "request": {
    "method": "ANY",
    "urlPattern": "/proxy-test/.*"
  },
  "response": {
    "proxyBaseUrl" : "https://localhost:8099",
    "proxyUrlPrefixToRemove" : "/proxy-test"
  }
}

Use the setting "--global-response-templating".

When sending a request to '/proxy-test/foo'
Expected behaviour: a proxy request to https://localhost:8099/foo
Actual behaviour: a proxy request to https://localhost:8099/proxy-test/foo

@davidseidel
Copy link

I'm facing the same problem, when I try to use this proxy feature. A fix would be great.

@pyrinoff
Copy link

pyrinoff commented Feb 6, 2022

Same problem. Tryed to create a mock with a mock/intercept pattern.
First of all, tryed to create proxy: for example, my mock will be at "myserver/smartMock", target request should be "otherserver/original".

{

"mappings": [{
        "request": {
            "urlPath": "/original",
            "method": "POST"
        },
        "response": {
            "body": "ORIGINAL RESPONSE"
        }
    }, {
        "request": {
            "urlPath": "/smartMock",
            "method": "POST"
        },
        "response": {
            "proxyBaseUrl": "http://localhost:8112/original",
            "proxyUrlPrefixToRemove": "/smartMock"
        }
    }
]

}

Result: Request was not matched
Closest stub [path] /smartMock
Request /smartMock/original <<<<< URL does not match

/smartMock should route to /original, but /smartMock didnt cut!

Tryed different variants, nothing works for me.
For this variant:

"proxyBaseUrl": "http://localhost:8112",

request didnt work at all! Only proxyBaseUrl with end "/" is working.

@grahambunce
Copy link

hi - any idea which release (and associated docker container update) this is fix scheduled for? FYI, documentation refers to this feature so newbies (like me) can get confused when it doesn't work as described :)

@sergey-karazhenets
Copy link

sergey-karazhenets commented Aug 8, 2022

Still reproduces in version 2.33.2 with option --global-response-templating.
But it works properly with option --local-response-templating.

@balint-backmaker
Copy link

hi @sergey-karazhenets awesome news and thanks for the effort!

Just to be clear, this means when we use --local-response-templating it means we need to add "transformers": ["response-template"] to the mappings we want to enabled it for, right? I read through the docs a few times over and this is how I interpreted it, but it never says explicitly that transformers is directly linked.

The reason for asking is I'm experiencing the same issue and some other flaky behaviour but wanted to test my muppetry thoroughly before I give more feedback on the issue.

Thanks for the answer in advance!

@balint-backmaker
Copy link

balint-backmaker commented Sep 5, 2022

Note to future readers: --local-response-templating does not mean that you can use the proxyUrlPrefixToRemove in the same mapping as your templated proxy.

here is a pair of working examples, assuming you've ran wiremock with --local-response-templating:

{
  "priority": 2,
  "request": {
    "urlPattern": "/.*",
    "headers": {
      "X-WM-PROXY-TARGET": {
        "matches": ".*"
      }
    }
  },
  "response": {
    "proxyBaseUrl": "https://{{request.headers.X-WM-PROXY-TARGET}}.example.com",
    "transformers": ["response-template"],
    "additionalProxyRequestHeaders": {
      "cf-access-token": "{{systemValue type='ENVIRONMENT' key='CF_OPS_TOKEN'}}"
    }
  }
}

And then you can do a self-redirect like so:

{
  "priority": 1,
  "request": {
    "urlPattern": "/my-prefix/.*",
    "headers": {
      "X-WM-PROXY-TARGET": {
        "absent": true
      }
    }
  },
  "response": {
    "proxyBaseUrl": "http://localhost:8080",
    "proxyUrlPrefixToRemove": "/my-prefix",
    "additionalProxyRequestHeaders": {
      "X-WM-PROXY-TARGET": "my-target"
    }
  }
}

I hope this helps! 🙂

@tomakehurst
Copy link
Member

Fixed in 9aad878

@tomakehurst
Copy link
Member

Fixed in 9aad878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants