mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 17:45:35 +00:00
aiohttp: Add support to allow_redirects option
This commit is contained in:
committed by
Jair Henrique
parent
f5ea0304da
commit
3da66c8dee
@@ -116,14 +116,15 @@ def _deserialize_headers(headers):
|
|||||||
return CIMultiDictProxy(deserialized_headers)
|
return CIMultiDictProxy(deserialized_headers)
|
||||||
|
|
||||||
|
|
||||||
def play_responses(cassette, vcr_request):
|
def play_responses(cassette, vcr_request, kwargs):
|
||||||
history = []
|
history = []
|
||||||
|
allow_redirects = kwargs.get("allow_redirects", True)
|
||||||
vcr_response = cassette.play_response(vcr_request)
|
vcr_response = cassette.play_response(vcr_request)
|
||||||
response = build_response(vcr_request, vcr_response, history)
|
response = build_response(vcr_request, vcr_response, history)
|
||||||
|
|
||||||
# If we're following redirects, continue playing until we reach
|
# If we're following redirects, continue playing until we reach
|
||||||
# our final destination.
|
# our final destination.
|
||||||
while 300 <= response.status <= 399:
|
while allow_redirects and 300 <= response.status <= 399:
|
||||||
if "location" not in response.headers:
|
if "location" not in response.headers:
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -256,7 +257,7 @@ def vcr_request(cassette, real_request):
|
|||||||
|
|
||||||
if cassette.can_play_response_for(vcr_request):
|
if cassette.can_play_response_for(vcr_request):
|
||||||
log.info("Playing response for {} from cassette".format(vcr_request))
|
log.info("Playing response for {} from cassette".format(vcr_request))
|
||||||
response = play_responses(cassette, vcr_request)
|
response = play_responses(cassette, vcr_request, kwargs)
|
||||||
for redirect in response.history:
|
for redirect in response.history:
|
||||||
self._cookie_jar.update_cookies(redirect.cookies, redirect.url)
|
self._cookie_jar.update_cookies(redirect.cookies, redirect.url)
|
||||||
self._cookie_jar.update_cookies(response.cookies, response.url)
|
self._cookie_jar.update_cookies(response.cookies, response.url)
|
||||||
|
|||||||
Reference in New Issue
Block a user