Use Track Mutators to modify requests and responses
masterMutators allow you to transform HTTP traffic. govcr protects live traffic from in-place modification, so mutators are used to transform data at specific lifecycle stages.
Types of Mutators
- Track Recording Mutator: Changes the request and/or response before they are persisted to the cassette file.
- Track Replaying Mutator: Transforms a track after it has been matched and retrieved from the cassette, but before it is returned to the caller. This does not modify the cassette file. Replaying mutators can access an informational copy of the current HTTP request via
Track.Response.Requestto tailor the response.
Predicates and Conditions
Mutators are applied based on On conditions. You can compose complex logic using these helper functions:
Any(...): Logical OR.All(...): Logical AND.Not(...): Logical NOT.None(...): Synonymous withNot(Any(...)).
Example of conditional application:
myMutator.
On(Any(...)).
On(Not(Any(...))).
On(Not(All(...)))