-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bot): http client perf issue (#852)
Work around for a perf issue with how httpx handles SSL. Instead of using `httpx.AsyncClient` directly, we subclass and reuse the ssl context. rel: encode/httpx#838
- Loading branch information
Showing
10 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from __future__ import annotations | ||
|
||
import ssl | ||
|
||
from httpx import ( # noqa: I251 | ||
AsyncClient, | ||
HTTPError, | ||
HTTPStatusError, | ||
Request, | ||
Response, | ||
) | ||
from httpx._config import DEFAULT_TIMEOUT_CONFIG # noqa: I251 | ||
from httpx._types import TimeoutTypes # noqa: I251 | ||
|
||
__all__ = ["Response", "Request", "HTTPError", "HttpClient", "HTTPStatusError"] | ||
|
||
# NOTE: this has a cost to create so we may want to set this lazily on the first HttpClient creation | ||
context = ssl.create_default_context() | ||
|
||
|
||
class HttpClient(AsyncClient): | ||
""" | ||
HTTP Client with the SSL config cached at the module level to avoid perf issues. | ||
see: https://github.com/encode/httpx/issues/838 | ||
""" | ||
|
||
def __init__( | ||
self, | ||
*, | ||
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG, | ||
): | ||
|
||
super().__init__( | ||
verify=context, | ||
timeout=timeout, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters