Switch follow redirects default (#1808)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Switch default on allow_redirects to False * allow_redirects -> follow_redirects * Update follow_redirects default in top-level API * Update docs on follow_redirects
authored by Tom Christie · committed by GitHub · parent 0b4a832 · Browse files · 8 files·+218 added−160 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
8 files+218 added−160 removed
- tests:+53 added−31 removed
- other:+165 added−129 removed
Provenance
- Commit
47266d7- Tree
6ac7a23- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
0b4a832
8 files changed+218 added−160 removed
modified:docs/compatibility.md+64 added-34 removed
2 unmodified lines345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717214 unmodified lines8788899091929394959697989910071 unmodified lines1721731741751131141151161171181191201211221231241251261761771781791311801811821831847 unmodified lines1921931941951471481491501511521531541551561571581591601611621631641651961971981993 unmodified lines2 unmodified linesHTTPX aims to be broadly compatible with the `requests` API.
This documentation outlines places where the API differs...
## Client instances
The HTTPX equivalent of `requests.Session` is `httpx.Client`.
```pythonsession = requests.Session(**kwargs)```
is generally equivalent to
```pythonclient = httpx.Client(**kwargs)```
## Request URLs
Accessing `response.url` will return a `URL` instance, rather than a string.
Use `str(response.url)` if you need a string instance.
## Redirects
Unlike `requests`, HTTPX does **not follow redirects by default**.
We differ in behaviour here [because auto-redirects can easily mask unnecessary networkcalls being made](https://github.com/encode/httpx/discussions/1785).
You can still enable behaviour to automatically follow redirects, but you need todo so explicitly...
```pythonrespose = client.get(url, follow_redirects=True)```
Or else instantiate a client, with redirect following enabled by default...
```pythonclient = httpx.Client(follow_redirects=True)```
## Determining the next redirect request
The `requests` library exposes an attribute `response.next`, which can be used to obtain the next redirect request.
```pythonsession = requests.Session()request = requests.Request("GET", ...).prepare()while request is not None: response = session.send(request, allow_redirects=False) request = response.next```
In HTTPX, this attribute is instead named `response.next_request`. For example:
```pythonclient = httpx.Client()request = client.build_request("GET", ...)while request is not None: response = client.send(request) request = response.next_request```
## Request Content
For uploading raw text or binary content we prefer to use a `content` parameter,in order to better separate this usage from the case of uploading form data.14 unmodified lines
Using the `data=<text/byte content>` will raise a deprecation warning,and is expected to be fully removed with the HTTPX 1.0 release.
## Upload files
HTTPX strictly enforces that upload files must be opened in binary mode, in orderto avoid character encoding issues that can result from attempting to upload filesopened in text mode.
## Content encoding
HTTPX uses `utf-8` for encoding `str` request bodies. For example, when using `content=<str>` the request body will be encoded to `utf-8` before being sent over the wire. This differs from Requests which uses `latin1`. If you need an explicit encoding, pass encoded bytes explictly, e.g. `content=<str>.encode("latin1")`.
71 unmodified lines## Checking for 4xx/5xx responses
We don't support `response.is_ok` since the naming is ambiguous there, and might incorrectly imply an equivalence to `response.status_code == codes.OK`. Instead we provide the `response.is_error` property. Use `if not response.is_error:` instead of `if response.is_ok:`.
## Client instances
The HTTPX equivalent of `requests.Session` is `httpx.Client`.
```pythonsession = requests.Session(**kwargs)```
is generally equivalent to
```pythonclient = httpx.Client(**kwargs)```
## Request instantiation
There is no notion of [prepared requests](https://requests.readthedocs.io/en/stable/user/advanced/#prepared-requests) in HTTPX. If you need to customize request instantiation, see [Request instances](advanced.md#request-instances).
Besides, `httpx.Request()` does not support the `auth`, `timeout`, `allow_redirects`, `proxies`, `verify` and `cert` parameters. However these are available in `httpx.request`, `httpx.get`, `httpx.post` etc., as well as on [`Client` instances](advanced.md#client-instances).Besides, `httpx.Request()` does not support the `auth`, `timeout`, `follow_redirects`, `proxies`, `verify` and `cert` parameters. However these are available in `httpx.request`, `httpx.get`, `httpx.post` etc., as well as on [`Client` instances](advanced.md#client-instances).
## Mocking
If you need to mock HTTPX the same way that test utilities like `responses` and `requests-mock` does for `requests`, see [RESPX](https://github.com/lundberg/respx).7 unmodified lines## Query Parameters
`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.
In HTTPX, this attribute is instead named `response.next_request`. For example:
```pythonclient = httpx.Client()request = client.build_request("GET", ...)while request is not None: response = client.send(request, allow_redirects=False) request = response.next_request```
## Event Hooks
`requests` allows event hooks to mutate `Request` and `Response` objects. See [examples](https://requests.readthedocs.io/en/master/user/advanced/#event-hooks) given in the documentation for `requests`.
3 unmodified linesmodified:docs/quickstart.md+19 added-17 removed
126 unmodified lines127 128 To include additional headers in the outgoing request, use the `headers` keyword argument:129 130 ```pycon131->>> url = 'http://httpbin.org/headers'131+>>> url = 'https://httpbin.org/headers'132 >>> headers = {'user-agent': 'my-app/0.0.1'}133 >>> r = httpx.get(url, headers=headers)134 ```135 243 unmodified lines379 380 Any cookies that are set on the response can be easily accessed:381 382 ```pycon383->>> r = httpx.get('http://httpbin.org/cookies/set?chocolate=chip', allow_redirects=False)383+>>> r = httpx.get('https://httpbin.org/cookies/set?chocolate=chip')384 >>> r.cookies['chocolate']385 'chip'386 ```387 388 To include cookies in an outgoing request, use the `cookies` parameter:389 390 ```pycon391 >>> cookies = {"peanut": "butter"}392->>> r = httpx.get('http://httpbin.org/cookies', cookies=cookies)392+>>> r = httpx.get('https://httpbin.org/cookies', cookies=cookies)393 >>> r.json()394 {'cookies': {'peanut': 'butter'}}395 ```396 10 unmodified lines407 ```408 409 ## Redirection and History410 411-By default, HTTPX will follow redirects for all HTTP methods.411+By default, HTTPX will **not** follow redirects for all HTTP methods, although412+this can be explicitly enabled.413 413-414-The `history` property of the response can be used to inspect any followed redirects.415-It contains a list of any redirect responses that were followed, in the order416-in which they were made.417-414 For example, GitHub redirects all HTTP requests to HTTPS.415 416 ```pycon417 >>> r = httpx.get('http://github.com/')422->>> r.url423-URL('https://github.com/')418 >>> r.status_code425-200419+301420 >>> r.history427-[<Response [301 Moved Permanently]>]421+[]422+>>> r.next_request423+<Request('GET', 'https://github.com/')>424 ```425 430-You can modify the default redirection handling with the allow_redirects parameter:426+You can modify the default redirection handling with the `follow_redirects` parameter:427 428 ```pycon433->>> r = httpx.get('http://github.com/', allow_redirects=False)429+>>> r = httpx.get('http://github.com/', follow_redirects=True)430+>>> r.url431+URL('https://github.com/')432 >>> r.status_code435-301433+200434 >>> r.history437-[]435+[<Response [301 Moved Permanently]>]436 ```437 438+The `history` property of the response can be used to inspect any followed redirects.439+It contains a list of any redirect responses that were followed, in the order440+in which they were made.441+442 ## Timeouts443 444 HTTPX defaults to including reasonable timeouts for all network operations,445 meaning that if a connection is not properly established then it should always39 unmodified linesmodified:httpx/_api.py+19 added-19 removed
32 unmodified lines33 cookies: CookieTypes = None,34 auth: AuthTypes = None,35 proxies: ProxiesTypes = None,36 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,37- allow_redirects: bool = True,37+ follow_redirects: bool = False,38 verify: VerifyTypes = True,39 cert: CertTypes = None,40 trust_env: bool = True,41 ) -> Response:23 unmodified lines65 request.66 * **proxies** - *(optional)* A dictionary mapping proxy keys to proxy URLs.67 * **timeout** - *(optional)* The timeout configuration to use when sending68 the request.69- * **allow_redirects** - *(optional)* Enables or disables HTTP redirects.69+ * **follow_redirects** - *(optional)* Enables or disables HTTP redirects.70 * **verify** - *(optional)* SSL certificates (a.k.a CA bundle) used to71 verify the identity of requested hosts. Either `True` (default CA bundle),72 a path to an SSL certificate file, an `ssl.SSLContext`, or `False`73 (which will disable verification).32 unmodified lines106 json=json,107 params=params,108 headers=headers,109 auth=auth,110- allow_redirects=allow_redirects,110+ follow_redirects=follow_redirects,111 )112 113 114 @contextmanager10 unmodified lines125 cookies: CookieTypes = None,126 auth: AuthTypes = None,127 proxies: ProxiesTypes = None,128 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,129- allow_redirects: bool = True,129+ follow_redirects: bool = False,130 verify: VerifyTypes = True,131 cert: CertTypes = None,132 trust_env: bool = True,133 ) -> typing.Iterator[Response]:24 unmodified lines158 json=json,159 params=params,160 headers=headers,161 auth=auth,162- allow_redirects=allow_redirects,162+ follow_redirects=follow_redirects,163 ) as response:164 yield response165 166 4 unmodified lines171 headers: HeaderTypes = None,172 cookies: CookieTypes = None,173 auth: AuthTypes = None,174 proxies: ProxiesTypes = None,175- allow_redirects: bool = True,175+ follow_redirects: bool = False,176 cert: CertTypes = None,177 verify: VerifyTypes = True,178 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,179 trust_env: bool = True,13 unmodified lines193 headers=headers,194 cookies=cookies,195 auth=auth,196 proxies=proxies,197- allow_redirects=allow_redirects,197+ follow_redirects=follow_redirects,198 cert=cert,199 verify=verify,200 timeout=timeout,201 trust_env=trust_env,7 unmodified lines209 headers: HeaderTypes = None,210 cookies: CookieTypes = None,211 auth: AuthTypes = None,212 proxies: ProxiesTypes = None,213- allow_redirects: bool = True,213+ follow_redirects: bool = False,214 cert: CertTypes = None,215 verify: VerifyTypes = True,216 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,217 trust_env: bool = True,13 unmodified lines231 headers=headers,232 cookies=cookies,233 auth=auth,234 proxies=proxies,235- allow_redirects=allow_redirects,235+ follow_redirects=follow_redirects,236 cert=cert,237 verify=verify,238 timeout=timeout,239 trust_env=trust_env,7 unmodified lines247 headers: HeaderTypes = None,248 cookies: CookieTypes = None,249 auth: AuthTypes = None,250 proxies: ProxiesTypes = None,251- allow_redirects: bool = True,251+ follow_redirects: bool = False,252 cert: CertTypes = None,253 verify: VerifyTypes = True,254 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,255 trust_env: bool = True,13 unmodified lines269 headers=headers,270 cookies=cookies,271 auth=auth,272 proxies=proxies,273- allow_redirects=allow_redirects,273+ follow_redirects=follow_redirects,274 cert=cert,275 verify=verify,276 timeout=timeout,277 trust_env=trust_env,11 unmodified lines289 headers: HeaderTypes = None,290 cookies: CookieTypes = None,291 auth: AuthTypes = None,292 proxies: ProxiesTypes = None,293- allow_redirects: bool = True,293+ follow_redirects: bool = False,294 cert: CertTypes = None,295 verify: VerifyTypes = True,296 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,297 trust_env: bool = True,14 unmodified lines312 headers=headers,313 cookies=cookies,314 auth=auth,315 proxies=proxies,316- allow_redirects=allow_redirects,316+ follow_redirects=follow_redirects,317 cert=cert,318 verify=verify,319 timeout=timeout,320 trust_env=trust_env,11 unmodified lines332 headers: HeaderTypes = None,333 cookies: CookieTypes = None,334 auth: AuthTypes = None,335 proxies: ProxiesTypes = None,336- allow_redirects: bool = True,336+ follow_redirects: bool = False,337 cert: CertTypes = None,338 verify: VerifyTypes = True,339 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,340 trust_env: bool = True,14 unmodified lines355 headers=headers,356 cookies=cookies,357 auth=auth,358 proxies=proxies,359- allow_redirects=allow_redirects,359+ follow_redirects=follow_redirects,360 cert=cert,361 verify=verify,362 timeout=timeout,363 trust_env=trust_env,11 unmodified lines375 headers: HeaderTypes = None,376 cookies: CookieTypes = None,377 auth: AuthTypes = None,378 proxies: ProxiesTypes = None,379- allow_redirects: bool = True,379+ follow_redirects: bool = False,380 cert: CertTypes = None,381 verify: VerifyTypes = True,382 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,383 trust_env: bool = True,14 unmodified lines398 headers=headers,399 cookies=cookies,400 auth=auth,401 proxies=proxies,402- allow_redirects=allow_redirects,402+ follow_redirects=follow_redirects,403 cert=cert,404 verify=verify,405 timeout=timeout,406 trust_env=trust_env,7 unmodified lines414 headers: HeaderTypes = None,415 cookies: CookieTypes = None,416 auth: AuthTypes = None,417 proxies: ProxiesTypes = None,418- allow_redirects: bool = True,418+ follow_redirects: bool = False,419 cert: CertTypes = None,420 verify: VerifyTypes = True,421 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,422 trust_env: bool = True,13 unmodified lines436 headers=headers,437 cookies=cookies,438 auth=auth,439 proxies=proxies,440- allow_redirects=allow_redirects,440+ follow_redirects=follow_redirects,441 cert=cert,442 verify=verify,443 timeout=timeout,444 trust_env=trust_env,1 unmodified linemodified:httpx/_client.py+62 added-58 removed
163 unmodified lines164 params: QueryParamTypes = None,165 headers: HeaderTypes = None,166 cookies: CookieTypes = None,167 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,168- allow_redirects: bool = True,168+ follow_redirects: bool = False,169 max_redirects: int = DEFAULT_MAX_REDIRECTS,170 event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None,171 base_url: URLTypes = "",172 trust_env: bool = True,6 unmodified lines179 self._params = QueryParams(params)180 self.headers = Headers(headers)181 self._cookies = Cookies(cookies)182 self._timeout = Timeout(timeout)183- self.allow_redirects = allow_redirects183+ self.follow_redirects = follow_redirects184 self.max_redirects = max_redirects185 self._event_hooks = {186 "request": list(event_hooks.get("request", [])),187 "response": list(event_hooks.get("response", [])),424 unmodified lines612 http2: bool = False,613 proxies: ProxiesTypes = None,614 mounts: typing.Mapping[str, BaseTransport] = None,615 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,616+ follow_redirects: bool = False,617 limits: Limits = DEFAULT_LIMITS,618 max_redirects: int = DEFAULT_MAX_REDIRECTS,619 event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None,620 base_url: URLTypes = "",6 unmodified lines627 params=params,628 headers=headers,629 cookies=cookies,630 timeout=timeout,631+ follow_redirects=follow_redirects,632 max_redirects=max_redirects,633 event_hooks=event_hooks,634 base_url=base_url,635 trust_env=trust_env,111 unmodified lines747 params: QueryParamTypes = None,748 headers: HeaderTypes = None,749 cookies: CookieTypes = None,750 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,749- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,751+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,752 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,753 ) -> Response:754 """755 Build and send a request.30 unmodified lines786 headers=headers,787 cookies=cookies,788 )789 return self.send(788- request, auth=auth, allow_redirects=allow_redirects, timeout=timeout790+ request, auth=auth, follow_redirects=follow_redirects, timeout=timeout791 )792 793 @contextmanager794 def stream(8 unmodified lines803 params: QueryParamTypes = None,804 headers: HeaderTypes = None,805 cookies: CookieTypes = None,806 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,805- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,807+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,808 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,809 ) -> typing.Iterator[Response]:810 """811 Alternative to `httpx.request()` that streams the response body18 unmodified lines830 )831 response = self.send(832 request=request,833 auth=auth,832- allow_redirects=allow_redirects,834+ follow_redirects=follow_redirects,835 timeout=timeout,836 stream=True,837 )838 try:6 unmodified lines845 request: Request,846 *,847 stream: bool = False,848 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,847- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,849+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,850 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,851 ) -> Response:852 """853 Send a request.14 unmodified lines868 self._state = ClientState.OPENED869 timeout = (870 self.timeout if isinstance(timeout, UseClientDefault) else Timeout(timeout)871 )870- allow_redirects = (871- self.allow_redirects872- if isinstance(allow_redirects, UseClientDefault)873- else allow_redirects872+ follow_redirects = (873+ self.follow_redirects874+ if isinstance(follow_redirects, UseClientDefault)875+ else follow_redirects876 )877 878 auth = self._build_request_auth(request, auth)879 880 response = self._send_handling_auth(881 request,882 auth=auth,883 timeout=timeout,882- allow_redirects=allow_redirects,884+ follow_redirects=follow_redirects,885 history=[],886 )887 try:888 if not stream:9 unmodified lines898 self,899 request: Request,900 auth: Auth,901 timeout: Timeout,900- allow_redirects: bool,902+ follow_redirects: bool,903 history: typing.List[Response],904 ) -> Response:905 auth_flow = auth.sync_auth_flow(request)906 try:2 unmodified lines909 while True:910 response = self._send_handling_redirects(911 request,912 timeout=timeout,911- allow_redirects=allow_redirects,913+ follow_redirects=follow_redirects,914 history=history,915 )916 try:917 try:15 unmodified lines933 def _send_handling_redirects(934 self,935 request: Request,936 timeout: Timeout,935- allow_redirects: bool,937+ follow_redirects: bool,938 history: typing.List[Response],939 ) -> Response:940 while True:941 if len(history) > self.max_redirects:15 unmodified lines957 958 request = self._build_redirect_request(request, response)959 history = history + [response]960 959- if allow_redirects:961+ if follow_redirects:962 response.read()963 else:964 response.next_request = request965 return response48 unmodified lines1014 params: QueryParamTypes = None,1015 headers: HeaderTypes = None,1016 cookies: CookieTypes = None,1017 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1016- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1018+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1019 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1020 ) -> Response:1021 """1022 Send a `GET` request.6 unmodified lines1029 params=params,1030 headers=headers,1031 cookies=cookies,1032 auth=auth,1031- allow_redirects=allow_redirects,1033+ follow_redirects=follow_redirects,1034 timeout=timeout,1035 )1036 1037 def options(3 unmodified lines1041 params: QueryParamTypes = None,1042 headers: HeaderTypes = None,1043 cookies: CookieTypes = None,1044 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1043- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1045+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1046 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1047 ) -> Response:1048 """1049 Send an `OPTIONS` request.6 unmodified lines1056 params=params,1057 headers=headers,1058 cookies=cookies,1059 auth=auth,1058- allow_redirects=allow_redirects,1060+ follow_redirects=follow_redirects,1061 timeout=timeout,1062 )1063 1064 def head(3 unmodified lines1068 params: QueryParamTypes = None,1069 headers: HeaderTypes = None,1070 cookies: CookieTypes = None,1071 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1070- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1072+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1073 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1074 ) -> Response:1075 """1076 Send a `HEAD` request.6 unmodified lines1083 params=params,1084 headers=headers,1085 cookies=cookies,1086 auth=auth,1085- allow_redirects=allow_redirects,1087+ follow_redirects=follow_redirects,1088 timeout=timeout,1089 )1090 1091 def post(7 unmodified lines1099 params: QueryParamTypes = None,1100 headers: HeaderTypes = None,1101 cookies: CookieTypes = None,1102 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1101- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1103+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1104 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1105 ) -> Response:1106 """1107 Send a `POST` request.10 unmodified lines1118 params=params,1119 headers=headers,1120 cookies=cookies,1121 auth=auth,1120- allow_redirects=allow_redirects,1122+ follow_redirects=follow_redirects,1123 timeout=timeout,1124 )1125 1126 def put(7 unmodified lines1134 params: QueryParamTypes = None,1135 headers: HeaderTypes = None,1136 cookies: CookieTypes = None,1137 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1136- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1138+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1139 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1140 ) -> Response:1141 """1142 Send a `PUT` request.10 unmodified lines1153 params=params,1154 headers=headers,1155 cookies=cookies,1156 auth=auth,1155- allow_redirects=allow_redirects,1157+ follow_redirects=follow_redirects,1158 timeout=timeout,1159 )1160 1161 def patch(7 unmodified lines1169 params: QueryParamTypes = None,1170 headers: HeaderTypes = None,1171 cookies: CookieTypes = None,1172 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1171- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1173+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1174 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1175 ) -> Response:1176 """1177 Send a `PATCH` request.10 unmodified lines1188 params=params,1189 headers=headers,1190 cookies=cookies,1191 auth=auth,1190- allow_redirects=allow_redirects,1192+ follow_redirects=follow_redirects,1193 timeout=timeout,1194 )1195 1196 def delete(3 unmodified lines1200 params: QueryParamTypes = None,1201 headers: HeaderTypes = None,1202 cookies: CookieTypes = None,1203 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1202- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1204+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1205 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1206 ) -> Response:1207 """1208 Send a `DELETE` request.6 unmodified lines1215 params=params,1216 headers=headers,1217 cookies=cookies,1218 auth=auth,1217- allow_redirects=allow_redirects,1219+ follow_redirects=follow_redirects,1220 timeout=timeout,1221 )1222 1223 def close(self) -> None:106 unmodified lines1330 http2: bool = False,1331 proxies: ProxiesTypes = None,1332 mounts: typing.Mapping[str, AsyncBaseTransport] = None,1333 timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,1334+ follow_redirects: bool = False,1335 limits: Limits = DEFAULT_LIMITS,1336 max_redirects: int = DEFAULT_MAX_REDIRECTS,1337 event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None,1338 base_url: URLTypes = "",6 unmodified lines1345 params=params,1346 headers=headers,1347 cookies=cookies,1348 timeout=timeout,1349+ follow_redirects=follow_redirects,1350 max_redirects=max_redirects,1351 event_hooks=event_hooks,1352 base_url=base_url,1353 trust_env=trust_env,110 unmodified lines1464 params: QueryParamTypes = None,1465 headers: HeaderTypes = None,1466 cookies: CookieTypes = None,1467 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1464- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1468+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1469 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1470 ) -> Response:1471 """1472 Build and send a request.22 unmodified lines1495 headers=headers,1496 cookies=cookies,1497 )1498 response = await self.send(1495- request, auth=auth, allow_redirects=allow_redirects, timeout=timeout1499+ request, auth=auth, follow_redirects=follow_redirects, timeout=timeout1500 )1501 return response1502 1503 @asynccontextmanager9 unmodified lines1513 params: QueryParamTypes = None,1514 headers: HeaderTypes = None,1515 cookies: CookieTypes = None,1516 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1513- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1517+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1518 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1519 ) -> typing.AsyncIterator[Response]:1520 """1521 Alternative to `httpx.request()` that streams the response body18 unmodified lines1540 )1541 response = await self.send(1542 request=request,1543 auth=auth,1540- allow_redirects=allow_redirects,1544+ follow_redirects=follow_redirects,1545 timeout=timeout,1546 stream=True,1547 )1548 try:6 unmodified lines1555 request: Request,1556 *,1557 stream: bool = False,1558 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1555- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1559+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1560 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1561 ) -> Response:1562 """1563 Send a request.14 unmodified lines1578 self._state = ClientState.OPENED1579 timeout = (1580 self.timeout if isinstance(timeout, UseClientDefault) else Timeout(timeout)1581 )1578- allow_redirects = (1579- self.allow_redirects1580- if isinstance(allow_redirects, UseClientDefault)1581- else allow_redirects1582+ follow_redirects = (1583+ self.follow_redirects1584+ if isinstance(follow_redirects, UseClientDefault)1585+ else follow_redirects1586 )1587 1588 auth = self._build_request_auth(request, auth)1589 1590 response = await self._send_handling_auth(1591 request,1592 auth=auth,1593 timeout=timeout,1590- allow_redirects=allow_redirects,1594+ follow_redirects=follow_redirects,1595 history=[],1596 )1597 try:1598 if not stream:9 unmodified lines1608 self,1609 request: Request,1610 auth: Auth,1611 timeout: Timeout,1608- allow_redirects: bool,1612+ follow_redirects: bool,1613 history: typing.List[Response],1614 ) -> Response:1615 auth_flow = auth.async_auth_flow(request)1616 try:2 unmodified lines1619 while True:1620 response = await self._send_handling_redirects(1621 request,1622 timeout=timeout,1619- allow_redirects=allow_redirects,1623+ follow_redirects=follow_redirects,1624 history=history,1625 )1626 try:1627 try:15 unmodified lines1643 async def _send_handling_redirects(1644 self,1645 request: Request,1646 timeout: Timeout,1643- allow_redirects: bool,1647+ follow_redirects: bool,1648 history: typing.List[Response],1649 ) -> Response:1650 while True:1651 if len(history) > self.max_redirects:16 unmodified lines1668 1669 request = self._build_redirect_request(request, response)1670 history = history + [response]1671 1668- if allow_redirects:1672+ if follow_redirects:1673 await response.aread()1674 else:1675 response.next_request = request1676 return response55 unmodified lines1732 params: QueryParamTypes = None,1733 headers: HeaderTypes = None,1734 cookies: CookieTypes = None,1735 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1732- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1736+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1737 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1738 ) -> Response:1739 """1740 Send a `GET` request.6 unmodified lines1747 params=params,1748 headers=headers,1749 cookies=cookies,1750 auth=auth,1747- allow_redirects=allow_redirects,1751+ follow_redirects=follow_redirects,1752 timeout=timeout,1753 )1754 1755 async def options(3 unmodified lines1759 params: QueryParamTypes = None,1760 headers: HeaderTypes = None,1761 cookies: CookieTypes = None,1762 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1759- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1763+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1764 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1765 ) -> Response:1766 """1767 Send an `OPTIONS` request.6 unmodified lines1774 params=params,1775 headers=headers,1776 cookies=cookies,1777 auth=auth,1774- allow_redirects=allow_redirects,1778+ follow_redirects=follow_redirects,1779 timeout=timeout,1780 )1781 1782 async def head(3 unmodified lines1786 params: QueryParamTypes = None,1787 headers: HeaderTypes = None,1788 cookies: CookieTypes = None,1789 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1786- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1790+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1791 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1792 ) -> Response:1793 """1794 Send a `HEAD` request.6 unmodified lines1801 params=params,1802 headers=headers,1803 cookies=cookies,1804 auth=auth,1801- allow_redirects=allow_redirects,1805+ follow_redirects=follow_redirects,1806 timeout=timeout,1807 )1808 1809 async def post(7 unmodified lines1817 params: QueryParamTypes = None,1818 headers: HeaderTypes = None,1819 cookies: CookieTypes = None,1820 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1817- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1821+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1822 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1823 ) -> Response:1824 """1825 Send a `POST` request.10 unmodified lines1836 params=params,1837 headers=headers,1838 cookies=cookies,1839 auth=auth,1836- allow_redirects=allow_redirects,1840+ follow_redirects=follow_redirects,1841 timeout=timeout,1842 )1843 1844 async def put(7 unmodified lines1852 params: QueryParamTypes = None,1853 headers: HeaderTypes = None,1854 cookies: CookieTypes = None,1855 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1852- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1856+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1857 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1858 ) -> Response:1859 """1860 Send a `PUT` request.10 unmodified lines1871 params=params,1872 headers=headers,1873 cookies=cookies,1874 auth=auth,1871- allow_redirects=allow_redirects,1875+ follow_redirects=follow_redirects,1876 timeout=timeout,1877 )1878 1879 async def patch(7 unmodified lines1887 params: QueryParamTypes = None,1888 headers: HeaderTypes = None,1889 cookies: CookieTypes = None,1890 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1887- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1891+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1892 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1893 ) -> Response:1894 """1895 Send a `PATCH` request.10 unmodified lines1906 params=params,1907 headers=headers,1908 cookies=cookies,1909 auth=auth,1906- allow_redirects=allow_redirects,1910+ follow_redirects=follow_redirects,1911 timeout=timeout,1912 )1913 1914 async def delete(3 unmodified lines1918 params: QueryParamTypes = None,1919 headers: HeaderTypes = None,1920 cookies: CookieTypes = None,1921 auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1918- allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1922+ follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,1923 timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,1924 ) -> Response:1925 """1926 Send a `DELETE` request.6 unmodified lines1933 params=params,1934 headers=headers,1935 cookies=cookies,1936 auth=auth,1933- allow_redirects=allow_redirects,1937+ follow_redirects=follow_redirects,1938 timeout=timeout,1939 )1940 1941 async def aclose(self) -> None:70 unmodified linesmodified:httpx/_models.py+1 added-1 removed
1207 unmodified lines1208 self.headers = Headers(headers)1209 1210 self._request: typing.Optional[Request] = request1211 1212- # When allow_redirects=False and a redirect is received,1212+ # When follow_redirects=False and a redirect is received,1213 # the client will set `response.next_request`.1214 self.next_request: typing.Optional[Request] = None1215 1216 self.extensions = {} if extensions is None else extensions646 unmodified linesmodified:tests/client/test_event_hooks.py+6 added-2 removed
129 unmodified lines130 131 event_hooks = {"request": [on_request], "response": [on_response]}132 133 with httpx.Client(134- event_hooks=event_hooks, transport=httpx.MockTransport(app)134+ event_hooks=event_hooks,135+ transport=httpx.MockTransport(app),136+ follow_redirects=True,137 ) as http:138 http.get("http://127.0.0.1:8000/redirect", auth=("username", "password"))139 140 assert events == [46 unmodified lines187 188 event_hooks = {"request": [on_request], "response": [on_response]}189 190 async with httpx.AsyncClient(189- event_hooks=event_hooks, transport=httpx.MockTransport(app)191+ event_hooks=event_hooks,192+ transport=httpx.MockTransport(app),193+ follow_redirects=True,194 ) as http:195 await http.get("http://127.0.0.1:8000/redirect", auth=("username", "password"))196 197 assert events == [31 unmodified linesmodified:tests/client/test_redirects.py+46 added-28 removed
111 unmodified lines112 113 114 def test_redirect_301():115 client = httpx.Client(transport=httpx.MockTransport(redirects))116- response = client.post("https://example.org/redirect_301")116+ response = client.post("https://example.org/redirect_301", follow_redirects=True)117 assert response.status_code == httpx.codes.OK118 assert response.url == "https://example.org/"119 assert len(response.history) == 1120 121 122 def test_redirect_302():123 client = httpx.Client(transport=httpx.MockTransport(redirects))124- response = client.post("https://example.org/redirect_302")124+ response = client.post("https://example.org/redirect_302", follow_redirects=True)125 assert response.status_code == httpx.codes.OK126 assert response.url == "https://example.org/"127 assert len(response.history) == 1128 129 130 def test_redirect_303():131 client = httpx.Client(transport=httpx.MockTransport(redirects))132- response = client.get("https://example.org/redirect_303")132+ response = client.get("https://example.org/redirect_303", follow_redirects=True)133 assert response.status_code == httpx.codes.OK134 assert response.url == "https://example.org/"135 assert len(response.history) == 1136 137 138 def test_next_request():139 client = httpx.Client(transport=httpx.MockTransport(redirects))140 request = client.build_request("POST", "https://example.org/redirect_303")141- response = client.send(request, allow_redirects=False)141+ response = client.send(request, follow_redirects=False)142 assert response.status_code == httpx.codes.SEE_OTHER143 assert response.url == "https://example.org/redirect_303"144 assert response.next_request is not None145 146- response = client.send(response.next_request, allow_redirects=False)146+ response = client.send(response.next_request, follow_redirects=False)147 assert response.status_code == httpx.codes.OK148 assert response.url == "https://example.org/"149 assert response.next_request is None150 1 unmodified line152 @pytest.mark.usefixtures("async_environment")153 async def test_async_next_request():154 async with httpx.AsyncClient(transport=httpx.MockTransport(redirects)) as client:155 request = client.build_request("POST", "https://example.org/redirect_303")156- response = await client.send(request, allow_redirects=False)156+ response = await client.send(request, follow_redirects=False)157 assert response.status_code == httpx.codes.SEE_OTHER158 assert response.url == "https://example.org/redirect_303"159 assert response.next_request is not None160 161- response = await client.send(response.next_request, allow_redirects=False)161+ response = await client.send(response.next_request, follow_redirects=False)162 assert response.status_code == httpx.codes.OK163 assert response.url == "https://example.org/"164 assert response.next_request is None165 2 unmodified lines168 """169 Contrary to Requests, redirects remain enabled by default for HEAD requests.170 """171 client = httpx.Client(transport=httpx.MockTransport(redirects))172- response = client.head("https://example.org/redirect_302")172+ response = client.head("https://example.org/redirect_302", follow_redirects=True)173 assert response.status_code == httpx.codes.OK174 assert response.url == "https://example.org/"175 assert response.request.method == "HEAD"176 assert len(response.history) == 11 unmodified line178 179 180 def test_relative_redirect():181 client = httpx.Client(transport=httpx.MockTransport(redirects))182- response = client.get("https://example.org/relative_redirect")182+ response = client.get(183+ "https://example.org/relative_redirect", follow_redirects=True184+ )185 assert response.status_code == httpx.codes.OK186 assert response.url == "https://example.org/"187 assert len(response.history) == 1188 189 190 def test_malformed_redirect():191 # https://github.com/encode/httpx/issues/771192 client = httpx.Client(transport=httpx.MockTransport(redirects))191- response = client.get("http://example.org/malformed_redirect")193+ response = client.get(194+ "http://example.org/malformed_redirect", follow_redirects=True195+ )196 assert response.status_code == httpx.codes.OK197 assert response.url == "https://example.org:443/"198 assert len(response.history) == 1199 200 201 def test_invalid_redirect():202 client = httpx.Client(transport=httpx.MockTransport(redirects))203 with pytest.raises(httpx.RemoteProtocolError):200- client.get("http://example.org/invalid_redirect")204+ client.get("http://example.org/invalid_redirect", follow_redirects=True)205 206 207 def test_no_scheme_redirect():208 client = httpx.Client(transport=httpx.MockTransport(redirects))205- response = client.get("https://example.org/no_scheme_redirect")209+ response = client.get(210+ "https://example.org/no_scheme_redirect", follow_redirects=True211+ )212 assert response.status_code == httpx.codes.OK213 assert response.url == "https://example.org/"214 assert len(response.history) == 1215 216 217 def test_fragment_redirect():218 client = httpx.Client(transport=httpx.MockTransport(redirects))213- response = client.get("https://example.org/relative_redirect#fragment")219+ response = client.get(220+ "https://example.org/relative_redirect#fragment", follow_redirects=True221+ )222 assert response.status_code == httpx.codes.OK223 assert response.url == "https://example.org/#fragment"224 assert len(response.history) == 1225 226 227 def test_multiple_redirects():228 client = httpx.Client(transport=httpx.MockTransport(redirects))221- response = client.get("https://example.org/multiple_redirects?count=20")229+ response = client.get(230+ "https://example.org/multiple_redirects?count=20", follow_redirects=True231+ )232 assert response.status_code == httpx.codes.OK233 assert response.url == "https://example.org/multiple_redirects"234 assert len(response.history) == 20235 assert response.history[0].url == "https://example.org/multiple_redirects?count=20"5 unmodified lines241 @pytest.mark.usefixtures("async_environment")242 async def test_async_too_many_redirects():243 async with httpx.AsyncClient(transport=httpx.MockTransport(redirects)) as client:244 with pytest.raises(httpx.TooManyRedirects):235- await client.get("https://example.org/multiple_redirects?count=21")245+ await client.get(246+ "https://example.org/multiple_redirects?count=21", follow_redirects=True247+ )248 249 250 def test_sync_too_many_redirects():251 client = httpx.Client(transport=httpx.MockTransport(redirects))252 with pytest.raises(httpx.TooManyRedirects):241- client.get("https://example.org/multiple_redirects?count=21")253+ client.get(254+ "https://example.org/multiple_redirects?count=21", follow_redirects=True255+ )256 257 258 def test_redirect_loop():259 client = httpx.Client(transport=httpx.MockTransport(redirects))260 with pytest.raises(httpx.TooManyRedirects):247- client.get("https://example.org/redirect_loop")261+ client.get("https://example.org/redirect_loop", follow_redirects=True)262 263 264 def test_cross_domain_redirect_with_auth_header():265 client = httpx.Client(transport=httpx.MockTransport(redirects))266 url = "https://example.com/cross_domain"267 headers = {"Authorization": "abc"}254- response = client.get(url, headers=headers)268+ response = client.get(url, headers=headers, follow_redirects=True)269 assert response.url == "https://example.org/cross_domain_target"270 assert "authorization" not in response.json()["headers"]271 272 273 def test_cross_domain_redirect_with_auth():274 client = httpx.Client(transport=httpx.MockTransport(redirects))275 url = "https://example.com/cross_domain"262- response = client.get(url, auth=("user", "pass"))276+ response = client.get(url, auth=("user", "pass"), follow_redirects=True)277 assert response.url == "https://example.org/cross_domain_target"278 assert "authorization" not in response.json()["headers"]279 280 281 def test_same_domain_redirect():282 client = httpx.Client(transport=httpx.MockTransport(redirects))283 url = "https://example.org/cross_domain"284 headers = {"Authorization": "abc"}271- response = client.get(url, headers=headers)285+ response = client.get(url, headers=headers, follow_redirects=True)286 assert response.url == "https://example.org/cross_domain_target"287 assert response.json()["headers"]["authorization"] == "abc"288 289 3 unmodified lines293 """294 client = httpx.Client(transport=httpx.MockTransport(redirects))295 url = "https://example.org/redirect_body"296 content = b"Example request body"283- response = client.post(url, content=content)297+ response = client.post(url, content=content, follow_redirects=True)298 assert response.url == "https://example.org/redirect_body_target"299 assert response.json()["body"] == "Example request body"300 assert "content-length" in response.json()["headers"]301 4 unmodified lines306 """307 client = httpx.Client(transport=httpx.MockTransport(redirects))308 url = "https://example.org/redirect_no_body"309 content = b"Example request body"296- response = client.post(url, content=content)310+ response = client.post(url, content=content, follow_redirects=True)311 assert response.url == "https://example.org/redirect_body_target"312 assert response.json()["body"] == ""313 assert "content-length" not in response.json()["headers"]314 315 316 def test_can_stream_if_no_redirect():317 client = httpx.Client(transport=httpx.MockTransport(redirects))318 url = "https://example.org/redirect_301"305- with client.stream("GET", url, allow_redirects=False) as response:319+ with client.stream("GET", url, follow_redirects=False) as response:320 assert not response.is_closed321 assert response.status_code == httpx.codes.MOVED_PERMANENTLY322 assert response.headers["location"] == "https://example.org/"323 5 unmodified lines329 def streaming_body():330 yield b"Example request body" # pragma: nocover331 332 with pytest.raises(httpx.StreamConsumed):319- client.post(url, content=streaming_body())333+ client.post(url, content=streaming_body(), follow_redirects=True)334 335 336 def test_cross_subdomain_redirect():337 client = httpx.Client(transport=httpx.MockTransport(redirects))338 url = "https://example.com/cross_subdomain"325- response = client.get(url)339+ response = client.get(url, follow_redirects=True)340 assert response.url == "https://www.example.org/cross_subdomain"341 342 343 def cookie_sessions(request: httpx.Request) -> httpx.Response:29 unmodified lines373 return httpx.Response(status_code, headers=headers)374 375 376 def test_redirect_cookie_behavior():363- client = httpx.Client(transport=httpx.MockTransport(cookie_sessions))377+ client = httpx.Client(378+ transport=httpx.MockTransport(cookie_sessions), follow_redirects=True379+ )380 381 # The client is not logged in.382 response = client.get("https://example.com/")383 assert response.url == "https://example.com/"22 unmodified lines406 407 def test_redirect_custom_scheme():408 client = httpx.Client(transport=httpx.MockTransport(redirects))409 with pytest.raises(httpx.UnsupportedProtocol) as e:394- client.post("https://example.org/redirect_custom_scheme")410+ client.post("https://example.org/redirect_custom_scheme", follow_redirects=True)411 assert str(e.value) == "Scheme 'market' not supported."412 413 414 @pytest.mark.usefixtures("async_environment")415 async def test_async_invalid_redirect():416 async with httpx.AsyncClient(transport=httpx.MockTransport(redirects)) as client:417 with pytest.raises(httpx.RemoteProtocolError):402- await client.get("http://example.org/invalid_redirect")418+ await client.get(419+ "http://example.org/invalid_redirect", follow_redirects=True420+ )modified:tests/test_utils.py+1 added-1 removed
118 unmodified lines119 120 @pytest.mark.asyncio121 async def test_logs_redirect_chain(server, capsys):122 with override_log_level("debug"):123- async with httpx.AsyncClient() as client:123+ async with httpx.AsyncClient(follow_redirects=True) as client:124 response = await client.get(server.url.copy_with(path="/redirect_301"))125 assert response.status_code == 200126 127 stderr = capsys.readouterr().err.strip()132 unmodified lines