cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

Add transformation functionality to "forward" #168

Closed cjstehno closed 1 year ago

cjstehno commented 1 year ago

Consider adding a means of transforming the outbound request (and possibly the incoming response) in the new "forward" functionality. Maybe something like:

server.expectations(expect -> {
    expect.GET("/something", req -> {
        req.forward(forwardEndpoint, tx -> {
            tx.request(r -> {
                // allow changing any part of the request before its sent to forward
            });
            tx.response(r -> {
                // allow changing any part of response after it comes in from forward
            });
        });
    });
});

This would increase the flexibility of the forwarding so that if you needed to make some alteration to the forwarded request or response, you don't have to modify your actual code, just some test config.

cjstehno commented 1 year ago

While this seems like an interesting idea, it's not trivial, so unless I get some interest in it, I am going to shelve it.