https://linen.dev logo
Title
t

Tanyagorn Benjaprompadung

01/30/2023, 12:47 PM
Hi Guys, I have similar problem to this https://stackoverflow.com/questions/41474410/can-wiremock-play-back-requests-from-multiple-domains and it's been 5 years already since this thread had been posted. Is there any update for support of record and playback for multiple target urls now?
t

Tom

01/30/2023, 12:53 PM
Hi @Tanyagorn Benjaprompadung it’s possible to record/playback multiple domains using forward proxying + snapshot recording. There is a little bit of effort involved. Essentially the process is: • Set up WireMock and your client for forward proxying per https://wiremock.org/docs/proxying/#running-as-a-browser-proxy • Generate some traffic from your client via the proxy. • Take a snapshot using the API, ensuring you include the
Host
header in the set of captured headers. For playback you can either continue to use forward proxying or configure a DNS alias for each target hostname you’ve recorded from.
Here’s a practical example: Start WireMock with templating and proxying enabled:
java -jar wiremock-jre8-standalone-2.35.0.jar \
  --enable-browser-proxying \
  --local-response-templating
Make some requests to varying domains (note we do this before recording, since we’re using the snapshot feature):
curl -v -k --proxy-insecure \
  --proxy localhost:8080 <https://api.github.com/users>
curl -v -k --proxy-insecure \
  --proxy localhost:8080 <https://wiremock.org/docs/>
Take a snapshot (essentially recording everything that’s already in the request log):
curl -v <http://localhost:8080/__admin/recordings/snapshot> -d '{
    "captureHeaders": {
        "Host" : {
          "caseInsensitive" : true
        }
    }
}'
Now if you check your stubs you’ll see you’ve got one for each request with host header matching configured:
curl <http://localhost:8080/__admin/mappings>
t

Tanyagorn Benjaprompadung

01/30/2023, 2:34 PM
@Tom Thanks for replying. Somehow I couldn't understand your example. Normally I just start recording by pressing button record in the recorder UI page at http://localhost:8080/__admin/recorder It is pretty simple and straight forward. From your practical example, how can I start recording traffic?
t

Tom

01/30/2023, 3:32 PM
Snapshotting is essentially recording after the fact - it takes the contents of the request log and treats it as a recording, even though you hadn’t started recording when the traffic arrived
The benefit at the moment of doing it this way (and we’ll fix this sometime soon) is that snapshotting doesn’t require a target URL for recording, whereas ordinary recording does
t

Tanyagorn Benjaprompadung

01/31/2023, 10:17 AM
@Tom I just tried what you have suggest. It's all working great! simpler than I originally thought. Thank you so much. This save a lot of my working time.
t

Tom

01/31/2023, 10:18 AM
Glad to hear it worked for you!
t

Tanyagorn Benjaprompadung

02/01/2023, 7:31 AM
Hello @Tom, how about taking a snapshot from https request? I have https expose at port 8443 and would like to take a snapshot from that as well. However, got problem with ssl certificate. Any suggestions?