Skip to content

Commit

Permalink
encode#1066 make BaseClient's auth and proxy accessible using getters…
Browse files Browse the repository at this point in the history
… and setters
  • Loading branch information
cdeler committed Aug 6, 2020
1 parent 0e73be8 commit 5191dc5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 9 additions & 1 deletion httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __init__(
self._params = QueryParams(params)
self._headers = Headers(headers)
self._cookies = Cookies(cookies)
self.timeout = Timeout(timeout)
self._timeout = Timeout(timeout)
self.max_redirects = max_redirects
self._trust_env = trust_env
self._netrc = NetRCInfo()
Expand Down Expand Up @@ -109,6 +109,14 @@ def _get_proxy_map(
proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies
return {"all": proxy}

@property
def timeout(self) -> Timeout:
return self._timeout

@timeout.setter
def timeout(self, timeout: TimeoutTypes) -> None:
self._timeout = Timeout(timeout)

@property
def base_url(self) -> URL:
"""
Expand Down
15 changes: 14 additions & 1 deletion tests/client/test_properties.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from httpx import URL, AsyncClient, Cookies, Headers
from httpx import URL, AsyncClient, Cookies, Headers, Timeout


def test_client_base_url():
Expand Down Expand Up @@ -36,3 +36,16 @@ def test_client_cookies():
mycookies = list(client.cookies.jar)
assert len(mycookies) == 1
assert mycookies[0].name == "a" and mycookies[0].value == "b"


def test_client_timeout():
expected_timeout = 12.0
client = AsyncClient()

client.timeout = expected_timeout # type: ignore

assert isinstance(client.timeout, Timeout)
assert client.timeout.connect == expected_timeout
assert client.timeout.read == expected_timeout
assert client.timeout.write == expected_timeout
assert client.timeout.pool == expected_timeout

0 comments on commit 5191dc5

Please sign in to comment.