diff --git a/tests/integration/test_httpx.py b/tests/integration/test_httpx.py index f7839347..46c90eaa 100644 --- a/tests/integration/test_httpx.py +++ b/tests/integration/test_httpx.py @@ -143,6 +143,21 @@ def test_redirect(tmpdir, do_request, yml): } +def test_preserve_redirect_method(tmpdir, do_request, yml): + url = "https://mockbin.org/redirect/307/1" + + response = do_request()("POST", url) + with vcr.use_cassette(yml): + response = do_request()("POST", url) + + with vcr.use_cassette(yml): + cassette_response = do_request()("POST", url) + + assert cassette_response.status_code == response.status_code + assert len(cassette_response.history) == len(response.history) + assert cassette_response.history[0].request.method == "POST" + + def test_work_with_gzipped_data(tmpdir, do_request, yml): with vcr.use_cassette(yml): do_request()("GET", "https://httpbin.org/gzip") diff --git a/vcr/stubs/httpx_stubs.py b/vcr/stubs/httpx_stubs.py index a22502c5..de55b4c9 100644 --- a/vcr/stubs/httpx_stubs.py +++ b/vcr/stubs/httpx_stubs.py @@ -108,7 +108,8 @@ def _play_responses(cassette, request, vcr_request, client, kwargs): if not next_url: break - vcr_request = VcrRequest("GET", next_url, None, dict(response.headers)) + method = request.method if response.status_code in [307, 308] else "GET" + vcr_request = VcrRequest(method, next_url, None, dict(response.headers)) vcr_request = cassette.find_requests_with_most_matches(vcr_request)[0][0] history.append(response)