From: Tom Christie Date: Tue, 10 Aug 2021 12:30:55 +0000 (+0100) Subject: Add Client(allow_redirect=<...>) (#1790) X-Git-Tag: 0.19.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=541a0afe5636248e5251894903b86ef17aaf5ebc;p=thirdparty%2Fhttpx.git Add Client(allow_redirect=<...>) (#1790) --- diff --git a/httpx/_client.py b/httpx/_client.py index c6e1efbe..9fd96c49 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -165,6 +165,7 @@ class BaseClient: headers: HeaderTypes = None, cookies: CookieTypes = None, timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, + allow_redirects: bool = True, max_redirects: int = DEFAULT_MAX_REDIRECTS, event_hooks: typing.Mapping[str, typing.List[typing.Callable]] = None, base_url: URLTypes = "", @@ -179,6 +180,7 @@ class BaseClient: self.headers = Headers(headers) self._cookies = Cookies(cookies) self._timeout = Timeout(timeout) + self.allow_redirects = allow_redirects self.max_redirects = max_redirects self._event_hooks = { "request": list(event_hooks.get("request", [])), @@ -744,7 +746,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -800,7 +802,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> typing.Iterator[Response]: """ @@ -842,7 +844,7 @@ class Client(BaseClient): *, stream: bool = False, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -865,6 +867,11 @@ class Client(BaseClient): timeout = ( self.timeout if isinstance(timeout, UseClientDefault) else Timeout(timeout) ) + allow_redirects = ( + self.allow_redirects + if isinstance(allow_redirects, UseClientDefault) + else allow_redirects + ) auth = self._build_request_auth(request, auth) @@ -1007,7 +1014,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1034,7 +1041,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1061,7 +1068,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1092,7 +1099,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1127,7 +1134,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1162,7 +1169,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1193,7 +1200,7 @@ class Client(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1448,7 +1455,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1497,7 +1504,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> typing.AsyncIterator[Response]: """ @@ -1539,7 +1546,7 @@ class AsyncClient(BaseClient): *, stream: bool = False, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1562,6 +1569,11 @@ class AsyncClient(BaseClient): timeout = ( self.timeout if isinstance(timeout, UseClientDefault) else Timeout(timeout) ) + allow_redirects = ( + self.allow_redirects + if isinstance(allow_redirects, UseClientDefault) + else allow_redirects + ) auth = self._build_request_auth(request, auth) @@ -1711,7 +1723,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1738,7 +1750,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1765,7 +1777,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1796,7 +1808,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1831,7 +1843,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1866,7 +1878,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """ @@ -1897,7 +1909,7 @@ class AsyncClient(BaseClient): headers: HeaderTypes = None, cookies: CookieTypes = None, auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT, - allow_redirects: bool = True, + allow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT, timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT, ) -> Response: """