Fix redirect description about HEAD (#1520)

* Fix redirect description about HEAD

* Apply suggestions from code review

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
This commit is contained in:
laggardkernel 2021-03-21 22:59:31 +08:00 committed by GitHub
parent e05a5372eb
commit ea5ffce14f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 11 deletions

View File

@ -124,6 +124,11 @@ On the other hand, HTTPX uses [HTTPCore](https://github.com/encode/httpcore) as
`requests` omits `params` whose values are `None` (e.g. `requests.get(..., params={"foo": None})`). This is not supported by HTTPX.
## HEAD redirection
In `requests`, all top-level API follow redirects by default except `HEAD`.
In consideration of consistency, we make `HEAD` follow redirects by default in 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.

View File

@ -408,7 +408,8 @@ with additional API for accessing cookies by their domain or path.
## Redirection and History
By default, HTTPX will follow redirects for anything except `HEAD` requests.
By default, HTTPX will follow redirects for all HTTP methods.
The `history` property of the response can be used to inspect any followed redirects.
It contains a list of any redirect responses that were followed, in the order
@ -436,16 +437,6 @@ You can modify the default redirection handling with the allow_redirects paramet
[]
```
If youre making a `HEAD` request, you can use this to enable redirection:
```pycon
>>> r = httpx.head('http://github.com/', allow_redirects=True)
>>> r.url
'https://github.com/'
>>> r.history
[<Response [301 Moved Permanently]>]
```
## Timeouts
HTTPX defaults to including reasonable timeouts for all network operations,