Skip to content

proxying

Bernard Niset edited this page Sep 11, 2022 · 3 revisions

(This documentation is adapted from the original documentation of WireMock.)

Mimus Serve has the ability to selectively proxy requests through to other hosts. This supports a proxy/intercept setup where requests are by default proxied to another (possibly real, live) service, but where specific stubs are configured these are returned in place of the remote service's response. Responses that the live service can't be forced to generate on demand can thus be injected for testing.

Proxy stub mappings

Proxy responses are defined in exactly the same manner as stubs, meaning that the same request matching criteria can be used.

The following code will proxy all GET requests made to http://<host>:<port>/other/service/.* to http://otherservice.com/approot, e.g. when running Mimus Serve locally a request to http://localhost:8080/other/service/doc/123 would be forwarded to http://otherservice.com/approot/other/service/doc/123.

{
  "request": {
    "method": "GET",
    "urlPattern": "/other/service/.*"
  },
  "response": {
    "proxyBaseUrl": "http://otherhost.com/approot"
  }
}

Remove path prefix

The prefix of a request path can be removed before proxying the request:

{
  "request": {
    "method": "GET",
    "url": "/other/service/doc/123"
  },
  "response": {
    "proxyBaseUrl": "http://otherhost.com/approot",
    "proxyUrlPrefixToRemove": "/other/service"
  }
}

Requests using the above path will be forwarded to http://otherhost.com/approot/doc/123

Additional headers (TODO)

It is possible to configure the proxy to add headers before forwarding the request to the destination:

{
  "request": {
    "method": "GET",
    "urlPattern": ".*"
  },
  "response": {
    "proxyBaseUrl": "http://otherhost.com",
    "additionalProxyRequestHeaders": {
      "User-Agent": "Mozilla/5.0 (iPhone; U; CPU iPhone)"
    }
  }
}

You can also add response headers via the same method as for non-proxy responses (see Stubbing).