@@ -116,15 +116,15 @@ def _deserialize_headers(headers):
116116 return CIMultiDictProxy (deserialized_headers )
117117
118118
119- def play_responses (cassette , vcr_request ):
119+ def play_responses (cassette , vcr_request , allow_redirects ):
120120 history = []
121121 vcr_response = cassette .play_response (vcr_request )
122122 response = build_response (vcr_request , vcr_response , history )
123123
124124 # If we're following redirects, continue playing until we reach
125125 # our final destination.
126126 while 300 <= response .status <= 399 :
127- if "location" not in response .headers :
127+ if "location" not in response .headers or allow_redirects is False :
128128 break
129129
130130 next_url = URL (response .url ).join (URL (response .headers ["location" ]))
@@ -237,6 +237,7 @@ async def new_request(self, method, url, **kwargs):
237237 data = kwargs .get ("data" , kwargs .get ("json" ))
238238 params = kwargs .get ("params" )
239239 cookies = kwargs .get ("cookies" )
240+ allow_redirects = kwargs .get ("allow_redirects" )
240241
241242 if auth is not None :
242243 headers ["AUTHORIZATION" ] = auth .encode ()
@@ -256,7 +257,7 @@ async def new_request(self, method, url, **kwargs):
256257
257258 if cassette .can_play_response_for (vcr_request ):
258259 log .info ("Playing response for {} from cassette" .format (vcr_request ))
259- response = play_responses (cassette , vcr_request )
260+ response = play_responses (cassette , vcr_request , allow_redirects )
260261 for redirect in response .history :
261262 self ._cookie_jar .update_cookies (redirect .cookies , redirect .url )
262263 self ._cookie_jar .update_cookies (response .cookies , response .url )
0 commit comments