From e7d334892f2b83d0a565db63440f6086e9590a1e Mon Sep 17 00:00:00 2001 From: Franko Morales <67804607+cochi2@users.noreply.github.com> Date: Mon, 20 Sep 2021 16:51:38 -0700 Subject: [PATCH] Fixing VCR redirection (#20747) Using the location passed as part of the redirection response if it is an absolute URL. --- tools/vcrpy/vcr/stubs/aiohttp_stubs/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/vcrpy/vcr/stubs/aiohttp_stubs/__init__.py b/tools/vcrpy/vcr/stubs/aiohttp_stubs/__init__.py index 48154aa7102e..6613819ee16a 100644 --- a/tools/vcrpy/vcr/stubs/aiohttp_stubs/__init__.py +++ b/tools/vcrpy/vcr/stubs/aiohttp_stubs/__init__.py @@ -95,7 +95,11 @@ def play_responses(cassette, vcr_request): # If we're following redirects, continue playing until we reach # our final destination. while 300 <= response.status <= 399: - next_url = URL(response.url).with_path(response.headers["location"]) + new_location = response.headers["location"] + potential_next_url = URL(new_location) + next_url = (potential_next_url + if potential_next_url.is_absolute() + else URL(response.url).with_path(new_location)) # Make a stub VCR request that we can then use to look up the recorded # VCR request saved to the cassette. This feels a little hacky and