Can we use wiremock as proxy server?

1,611 views
Skip to first unread message

SV

unread,
Dec 15, 2017, 8:48:26 AM12/15/17
to wiremock-user
Hello Everyone,

Can we use wiremock as a proxy server. Following is the scenario:

1. Launch wiremock as standalone/programatically(@http://localhost:8080 and --proxy-all "http://some.website.com")

2. Now launch browser with url http://localhost:8080, which will redirect to http://some.website.com

3. Now there is one javascript in http://some.website.com which calls to http://different.website.com. Now can we mock this http://different.website.com

Please let me know your thought and approach.

Here are following steps which I tried:

1. Launch : java -jar wiremock-standalone-2.12.0.jar --proxy-all http://some.website.com
2. Created following file:
    ./__file/body-different.txt
    ./mapping/mapping-different.json
3. Launch chrome with URL http://localhost:8080,  which redirected to http://some.website.com
4. Now here is the problem: The javascript in http://some.website.com tries to call http://different.website.com, but it is not getting response from local mapping file.

-> body-different.txt
{"key":"value"}

-> mapping-different.json
{
  "id" : "a1d96895-2574-306e-83e1-bb03c4498152",
  "request" : {
    "method" : "GET"
  },
  "response" : {
    "status" : 302,
    "bodyFileName" : "body-different.txt",
    "headers" : {
      "Connection" : "keep-alive"
    }
  },
  "uuid" : "a1d96895-2574-306e-83e1-bb03c4498152"
}

Tom Akehurst

unread,
Dec 15, 2017, 10:30:24 AM12/15/17
to wiremock-user
OK, provided all of the URLs being fetched are http (not https), then the easiest fix for this is probably to start WireMock with --enable-browser-proxying and set your browser's proxy server to be localhost 8080 (or whatever port you're using). That way all requests from your browser will go through WireMock and this gives you the opportunity to stub the requests you want to modify.

Failing that, I think your only recourse would be to write a ResponseTransformer that performed the search and replace on the domain name.

Note: the request "url" attribute has to be a relative URL, absolute URLs aren't permitted here.
Reply all
Reply to author
Forward
0 new messages