https://linen.dev logo
#general
Title
# general
j

Jackie chen

05/02/2023, 3:59 AM
I would like to know if wiremock supports multiple corporate proxies when we have multiple targets to proxy requests to e.g. one external domain needs proxyVia: “http://corperate.proxy1.com”, but there is another domain needs corporate proxy: “http://corperate.proxy2.com
Copy code
{
    "mappings":
    [
        {
            "request":
            {
                "urlPattern": "/api1"
            },
            "response":
            {
                "proxyBaseUrl": "<http://public.domain1.com>",
                "proxyVia": "<http://corperate.proxy1.com>"
            }
        },
        {
            "request":
            {
                "urlPattern": "/api2"
            },
            "response":
            {
                "proxyBaseUrl": "<http://public.domain2.com>",
                "proxyVia": "<http://corperate.proxy2.com>"
            }
        },
    ]
}
t

Tom

05/02/2023, 9:39 AM
Hi @Jackie chen, WireMock doesn’t support this unfortunately as it has a single HTTP client instance and thus a single set of proxy settings. The only solution I can think of off the top of my head (short of forking WireMock and customising it in this way) is to put e.g. an nginx instance in front of it to act as a single proxy, then configure this to route to the relevant corporate proxies.
j

Jackie chen

05/02/2023, 11:02 AM
@Tom thank you very much for the idea. This sounds good. Let me try to understand this. 1) initialize wiremock instance with proxyVia(nginx proxy) 2) configure this nginx proxy to route requests to the desired corporate proxy Then requests will be proxied via the desired corporate proxy and sent to the external destination. Is my understanding correct?
t

Tom

05/02/2023, 11:23 AM
Yes, that’s what I had in mind. Let me caveat - I’ve never actually tried this myself!
8 Views