Merge bb0bcd72c2 into b5addb64f0
This commit is contained in:
commit
f4eaf174a4
@ -980,13 +980,14 @@ class Client(BaseClient):
|
||||
try:
|
||||
for hook in self._event_hooks["response"]:
|
||||
hook(response)
|
||||
response.history = list(history)
|
||||
transport_history = response.history
|
||||
response.history = list(history) + transport_history
|
||||
|
||||
if not response.has_redirect_location:
|
||||
return response
|
||||
|
||||
request = self._build_redirect_request(request, response)
|
||||
history = history + [response]
|
||||
history = history + transport_history + [response]
|
||||
|
||||
if follow_redirects:
|
||||
response.read()
|
||||
@ -1695,14 +1696,14 @@ class AsyncClient(BaseClient):
|
||||
try:
|
||||
for hook in self._event_hooks["response"]:
|
||||
await hook(response)
|
||||
|
||||
response.history = list(history)
|
||||
transport_history = response.history
|
||||
response.history = list(history) + transport_history
|
||||
|
||||
if not response.has_redirect_location:
|
||||
return response
|
||||
|
||||
request = self._build_redirect_request(request, response)
|
||||
history = history + [response]
|
||||
history = history + transport_history + [response]
|
||||
|
||||
if follow_redirects:
|
||||
await response.aread()
|
||||
|
||||
@ -107,6 +107,12 @@ def redirects(request: httpx.Request) -> httpx.Response:
|
||||
headers = {"location": "market://details?id=42"}
|
||||
return httpx.Response(status_code, headers=headers)
|
||||
|
||||
elif request.url.path == "/redirect_303_with_history":
|
||||
status_code = httpx.codes.SEE_OTHER
|
||||
headers = {"location": "https://example.org/"}
|
||||
history = [httpx.Response(status_code, headers=headers)]
|
||||
return httpx.Response(status_code, headers=headers, history=history)
|
||||
|
||||
if request.method == "HEAD":
|
||||
return httpx.Response(200)
|
||||
|
||||
@ -445,3 +451,25 @@ async def test_async_invalid_redirect():
|
||||
await client.get(
|
||||
"http://example.org/invalid_redirect", follow_redirects=True
|
||||
)
|
||||
|
||||
|
||||
def test_redirect_303_history():
|
||||
client = httpx.Client(transport=httpx.MockTransport(redirects))
|
||||
response = client.get(
|
||||
"https://example.org/redirect_303_with_history", follow_redirects=True
|
||||
)
|
||||
assert response.status_code == httpx.codes.OK
|
||||
assert response.url == "https://example.org/"
|
||||
assert len(response.history) == 2
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_async_redirect_history():
|
||||
async with httpx.AsyncClient(transport=httpx.MockTransport(redirects)) as client:
|
||||
request = client.build_request(
|
||||
"POST", "https://example.org/redirect_303_with_history"
|
||||
)
|
||||
response = await client.send(request, follow_redirects=True)
|
||||
assert response.status_code == httpx.codes.OK
|
||||
assert response.url == "https://example.org/"
|
||||
assert len(response.history) == 2
|
||||
|
||||
Loading…
Reference in New Issue
Block a user