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

Global request expectation fragments #149

Closed cjstehno closed 2 years ago

cjstehno commented 2 years ago

Provide a means to specify base request matchers for ANY or specific methods such that all the requests with that method must match the provided criteria or be rejected.

These should NOT provide responders, but only request matchers.

Call them request requirements (?)

Something like:

server = new ErsatzServer(cfg -> {
    cfg.requires(q -> {
        q.ANY('*', req -> {
            req.header("Auth-Token", requiredToken);
        });
    });
});

Which would require that any request method against any path must have the specified header, or else be rejected.

This would be useful with the recent removal of direct BASIC auth support since its done per request now, as a matcher.

cjstehno commented 2 years ago

This has been implemented in 3.1