Skip to content

Commit

Permalink
Handle 307 and 308 redirect method in httpx
Browse files Browse the repository at this point in the history
  • Loading branch information
kestutisbalt committed Aug 18, 2020
1 parent 1d0fdba commit 86c3834
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions tests/integration/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion vcr/stubs/httpx_stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 86c3834

Please sign in to comment.