venmo / DVR

Network testing for Swift
http://blog.soff.es/network-testing-in-swift-with-dvr
MIT License
651 stars 86 forks source link

Select response based on request headers #96

Closed thasspp closed 3 years ago

thasspp commented 3 years ago

This package would be more helpful if it distinguished between identical requests with different headers. To accomplish this, we can add a new optional parameter to Session called requiredHeaders:

Session(
    cassetteName: "my-cassette", 
    backingSession: aBackingSession,
    requiredHeaders: ["some-header-that-might-warrant-a-different-response"]
)

Only the headers specified in the requiredHeaders parameter will be used to select the response in the cassette. This is because other request headers (like User-Agent) change often and would make testing more difficult. This is useful when a test needs to hit the same endpoint multiple times and expects different responses based on the request headers.

thasspp commented 3 years ago

@hyperspacemark @danhollywells @factotvm Maybe you can help review this?

thasspp commented 3 years ago

@factotvm Would you mind merging this when you get a change? I don't have write access.