::: httpx.delete
:docstring:
-
+
::: httpx.stream
:docstring:
* `.encoding` - **str**
* `.is_redirect` - **bool**
* `.request` - **Request**
+* `.next_request` - **Optional[Request]**
* `.cookies` - **Cookies**
* `.history` - **List[Response]**
* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**
## Query Parameters
`requests` omits `params` whose values are `None` (e.g. `requests.get(..., params={"foo": None})`). This is not supported by HTTPX.
+
+## Determining the next redirect request
+
+When using `allow_redirects=False`, the `requests` library exposes an attribute `response.next`, which can be used to obtain the next redirect request.
+
+In HTTPX, this attribute is instead named `response.next_request`. For example:
+
+```python
+client = httpx.Client()
+request = client.build_request("GET", ...)
+while request is not None:
+ response = client.send(request, allow_redirects=False)
+ request = response.next_request
+```
history = history + [response]
if not allow_redirects:
+ response.next_request = request
response.call_next = functools.partial(
self._send_handling_redirects,
request=request,
history = history + [response]
if not allow_redirects:
+ response.next_request = request
response.call_next = functools.partial(
self._send_handling_redirects,
request=request,
self._request: typing.Optional[Request] = request
+ # When allow_redirects=False and a redirect is received,
+ # the client will set `response.next_request`.
+ self.next_request: typing.Optional[Request] = None
+
self.call_next: typing.Optional[typing.Callable] = None
self.ext = {} if ext is None else ext
assert len(response.history) == 1
+def test_next_request():
+ client = httpx.Client(transport=MockTransport(redirects))
+ request = client.build_request("POST", "https://example.org/redirect_303")
+ response = client.send(request, allow_redirects=False)
+ assert response.status_code == httpx.codes.SEE_OTHER
+ assert response.url == "https://example.org/redirect_303"
+ assert response.next_request is not None
+
+ response = client.send(response.next_request, allow_redirects=False)
+ assert response.status_code == httpx.codes.OK
+ assert response.url == "https://example.org/"
+ assert response.next_request is None
+
+
def test_head_redirect():
"""
Contrary to Requests, redirects remain enabled by default for HEAD requests.