thoughtworks/pacto — pull request #145 by maxlinc (2014-08-01 18:05:10+00:00)
Title: Overridable body and headers

This PR allows the header or body to be overridden when using the consumer API to send simulated requests to a provider. The way it works is that the Actor produces a request as before (either based on an example or the JSON schema). The difference is that the caller can pass a proc to modify the body or headers before they are sent:

```ruby
interactions = Pacto.simulate_consumer :my_client do
request 'Ping'
request 'Echo', body: ->(body) { body.reverse },
headers: (proc do |headers|
headers['Content-Type'] = 'text/json'
headers['Accept'] = 'none'
headers
end)
```

This should unblock many tests that were problematic before, like tests that needed to inject or modify headers for authentication, UUIDs, or crypographic signatures.

Eventually better middleware or features may be available for common scenarios like injecting authentication information, but for now I think this is a simple workaround.