vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

Expose Request object so we can see if a replay occurred.

Open lewisdawson opened this issue 1 year ago • 1 comments

In some cases, we need to determine if the actual request was invoked or the cached version was returned. In order to do that, we need to do an evolution of #394. We need to reconstruct the underlying Request object:

import vcr

def make_vcr_request(req):
      body = req.read().decode("utf-8")
      uri = str(req.url)
      headers = dict(req.headers)
      return vcr.Request(req.method, uri, body, headers)


self._current_request_used_cache = self.cassete.can_play_response_for(make_vcr_request(request))

To do that, we need VCR's Request object exposed for use outside the package.

This PR simply exposes that Request object for use. Open to thoughts on how to better accomplish this by folks that know this tool better.

lewisdawson avatar Aug 12 '23 13:08 lewisdawson

@kevin1024 Any interest in merging this PR? It's a very simple change.

lewisdawson avatar Aug 28 '23 13:08 lewisdawson