mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Reuse value from Location header on redirect
Because the recoded requests are using original value. Changing the value on redirect prevents finding the matching response.
This commit is contained in:
committed by
Kevin McCarthy
parent
7d2d29de12
commit
133423ce94
@@ -97,29 +97,17 @@ def _record_responses(cassette, vcr_request, real_response):
|
||||
return real_response
|
||||
|
||||
|
||||
def _get_next_url(response):
|
||||
location_str = response.headers.get("location")
|
||||
if not location_str:
|
||||
return None
|
||||
|
||||
next_url = URL(location_str)
|
||||
if not next_url.is_absolute():
|
||||
next_url = URL(str(response.url)).with_path(str(next_url))
|
||||
|
||||
return next_url
|
||||
|
||||
|
||||
def _play_responses(cassette, request, vcr_request, client):
|
||||
history = []
|
||||
vcr_response = cassette.play_response(vcr_request)
|
||||
response = _from_serialized_response(request, vcr_response)
|
||||
|
||||
while 300 <= response.status_code <= 399:
|
||||
next_url = _get_next_url(response)
|
||||
next_url = response.headers.get("location")
|
||||
if not next_url:
|
||||
break
|
||||
|
||||
vcr_request = VcrRequest("GET", str(next_url), None, dict(response.headers))
|
||||
vcr_request = VcrRequest("GET", next_url, None, dict(response.headers))
|
||||
vcr_request = cassette.find_requests_with_most_matches(vcr_request)[0][0]
|
||||
|
||||
history.append(response)
|
||||
|
||||
Reference in New Issue
Block a user