Skip to content

Commit

Permalink
Version 0.21 (#1935)
Browse files Browse the repository at this point in the history
* Integrate with httpcore 0.14

* Fix pool timeout test

* Add request extensions to API

* Add certificate and connection info to client, using 'trace' extension

* Fix test_pool_timeout flakiness
  • Loading branch information
tomchristie authored Nov 15, 2021
1 parent c531263 commit 61188fe
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 117 deletions.
2 changes: 1 addition & 1 deletion httpx/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__title__ = "httpx"
__description__ = "A next generation HTTP client, for Python 3."
__version__ = "0.20.0"
__version__ = "0.21.0"
57 changes: 52 additions & 5 deletions httpx/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def build_request(
headers: HeaderTypes = None,
cookies: CookieTypes = None,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Request:
"""
Build and return a request instance.
Expand All @@ -339,9 +340,14 @@ def build_request(
headers = self._merge_headers(headers)
cookies = self._merge_cookies(cookies)
params = self._merge_queryparams(params)
timeout = (
self.timeout if isinstance(timeout, UseClientDefault) else Timeout(timeout)
)
extensions = {} if extensions is None else extensions
if "timeout" not in extensions:
timeout = (
self.timeout
if isinstance(timeout, UseClientDefault)
else Timeout(timeout)
)
extensions["timeout"] = timeout.as_dict()
return Request(
method,
url,
Expand All @@ -352,7 +358,7 @@ def build_request(
params=params,
headers=headers,
cookies=cookies,
extensions={"timeout": timeout.as_dict()},
extensions=extensions,
)

def _merge_url(self, url: URLTypes) -> URL:
Expand Down Expand Up @@ -459,7 +465,12 @@ def _build_redirect_request(self, request: Request, response: Response) -> Reque
stream = self._redirect_stream(request, method)
cookies = Cookies(self.cookies)
return Request(
method=method, url=url, headers=headers, cookies=cookies, stream=stream
method=method,
url=url,
headers=headers,
cookies=cookies,
stream=stream,
extensions=request.extensions,
)

def _redirect_method(self, request: Request, response: Response) -> str:
Expand Down Expand Up @@ -749,6 +760,7 @@ def request(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Build and send a request.
Expand Down Expand Up @@ -785,6 +797,7 @@ def request(
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
return self.send(request, auth=auth, follow_redirects=follow_redirects)

Expand All @@ -804,6 +817,7 @@ def stream(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> typing.Iterator[Response]:
"""
Alternative to `httpx.request()` that streams the response body
Expand All @@ -826,6 +840,7 @@ def stream(
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
response = self.send(
request=request,
Expand Down Expand Up @@ -1000,6 +1015,7 @@ def get(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `GET` request.
Expand All @@ -1015,6 +1031,7 @@ def get(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def options(
Expand All @@ -1027,6 +1044,7 @@ def options(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send an `OPTIONS` request.
Expand All @@ -1042,6 +1060,7 @@ def options(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def head(
Expand All @@ -1054,6 +1073,7 @@ def head(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `HEAD` request.
Expand All @@ -1069,6 +1089,7 @@ def head(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def post(
Expand All @@ -1085,6 +1106,7 @@ def post(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `POST` request.
Expand All @@ -1104,6 +1126,7 @@ def post(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def put(
Expand All @@ -1120,6 +1143,7 @@ def put(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `PUT` request.
Expand All @@ -1139,6 +1163,7 @@ def put(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def patch(
Expand All @@ -1155,6 +1180,7 @@ def patch(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `PATCH` request.
Expand All @@ -1174,6 +1200,7 @@ def patch(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def delete(
Expand All @@ -1186,6 +1213,7 @@ def delete(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `DELETE` request.
Expand All @@ -1201,6 +1229,7 @@ def delete(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

def close(self) -> None:
Expand Down Expand Up @@ -1450,6 +1479,7 @@ async def request(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Build and send a request.
Expand Down Expand Up @@ -1478,6 +1508,7 @@ async def request(
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
return await self.send(request, auth=auth, follow_redirects=follow_redirects)

Expand All @@ -1497,6 +1528,7 @@ async def stream(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> typing.AsyncIterator[Response]:
"""
Alternative to `httpx.request()` that streams the response body
Expand All @@ -1519,6 +1551,7 @@ async def stream(
headers=headers,
cookies=cookies,
timeout=timeout,
extensions=extensions,
)
response = await self.send(
request=request,
Expand Down Expand Up @@ -1693,6 +1726,7 @@ async def get(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `GET` request.
Expand All @@ -1708,6 +1742,7 @@ async def get(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def options(
Expand All @@ -1720,6 +1755,7 @@ async def options(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send an `OPTIONS` request.
Expand All @@ -1735,6 +1771,7 @@ async def options(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def head(
Expand All @@ -1747,6 +1784,7 @@ async def head(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `HEAD` request.
Expand All @@ -1762,6 +1800,7 @@ async def head(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def post(
Expand All @@ -1778,6 +1817,7 @@ async def post(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `POST` request.
Expand All @@ -1797,6 +1837,7 @@ async def post(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def put(
Expand All @@ -1813,6 +1854,7 @@ async def put(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `PUT` request.
Expand All @@ -1832,6 +1874,7 @@ async def put(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def patch(
Expand All @@ -1848,6 +1891,7 @@ async def patch(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `PATCH` request.
Expand All @@ -1867,6 +1911,7 @@ async def patch(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def delete(
Expand All @@ -1879,6 +1924,7 @@ async def delete(
auth: typing.Union[AuthTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
follow_redirects: typing.Union[bool, UseClientDefault] = USE_CLIENT_DEFAULT,
timeout: typing.Union[TimeoutTypes, UseClientDefault] = USE_CLIENT_DEFAULT,
extensions: dict = None,
) -> Response:
"""
Send a `DELETE` request.
Expand All @@ -1894,6 +1940,7 @@ async def delete(
auth=auth,
follow_redirects=follow_redirects,
timeout=timeout,
extensions=extensions,
)

async def aclose(self) -> None:
Expand Down
Loading

0 comments on commit 61188fe

Please sign in to comment.