Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add httpx.SSLContext configuration. #3022

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
88f2ab7
Add ssl_context argument
karpetrosyan Dec 25, 2023
58e9fdc
Use default ciphers and set minimum tls version to 1.2
karpetrosyan Dec 25, 2023
1afe2c9
Merge branch 'master' into add-ssl-context-argument
karpetrosyan Dec 28, 2023
6be802e
Fix init_proxy_transport arguments
karpetrosyan Dec 28, 2023
d124d8f
Merge branch 'master' into add-ssl-context-argument
karpetrosyan Dec 28, 2023
6f1162b
Use __init__ instead of __new__ in SSLContext
karpetrosyan Dec 29, 2023
f613dee
Merge branch 'master' into add-ssl-context-argument
karpetrosyan Jan 5, 2024
55ec002
Merge branch 'master' into add-ssl-context-argument
tomchristie Jan 15, 2024
7346bc2
Merge branch 'master' into add-ssl-context-argument
karpetrosyan Jan 16, 2024
7f35134
Docs
karpetrosyan Jan 16, 2024
8d5983a
Fix SSLContext repr
karpetrosyan Jan 16, 2024
f759dec
Merge branch 'master' into add-ssl-context-argument
karpetrosyan Jan 16, 2024
7227573
Merge branch 'master' into add-ssl-context-argument
tomchristie Mar 1, 2024
0567aab
Merge branch 'master' into add-ssl-context-argument
tomchristie Mar 1, 2024
2d79640
Fixes to merge master
tomchristie Mar 1, 2024
4d84953
comma
tomchristie Mar 1, 2024
df7bf31
Update _client.py
tomchristie Mar 1, 2024
93ca75f
Update _config.py
tomchristie Mar 1, 2024
2b7cf9e
Update _config.py
tomchristie Mar 1, 2024
fa065dd
Merge branch 'master' into add-ssl-context-argument
tomchristie May 8, 2024
f09a823
Merge branch 'master' into add-ssl-context-argument
karpetrosyan May 17, 2024
4eba150
Merge branch 'master' of github.com:encode/httpx into add-ssl-context…
karpetrosyan Sep 4, 2024
f3b1dc7
Merge branch 'master' into add-ssl-context-argument
karpetrosyan Sep 22, 2024
998f445
Merge branch 'master' into add-ssl-context-argument
tomchristie Sep 23, 2024
a08ff77
Update docs/advanced/ssl.md
karpetrosyan Sep 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions httpx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from ._api import delete, get, head, options, patch, post, put, request, stream
from ._auth import Auth, BasicAuth, DigestAuth, NetRCAuth
from ._client import USE_CLIENT_DEFAULT, AsyncClient, Client
from ._config import Limits, Proxy, Timeout, create_ssl_context
from ._config import Limits, Proxy, SSLContext, Timeout
from ._content import ByteStream
from ._exceptions import (
CloseError,
Expand Down Expand Up @@ -79,7 +79,6 @@ def main() -> None: # type: ignore
"ConnectTimeout",
"CookieConflict",
"Cookies",
"create_ssl_context",
"DecodingError",
"delete",
"DigestAuth",
Expand Down Expand Up @@ -114,6 +113,7 @@ def main() -> None: # type: ignore
"RequestNotRead",
"Response",
"ResponseNotRead",
"SSLContext",
"stream",
"StreamClosed",
"StreamConsumed",
Expand Down
68 changes: 21 additions & 47 deletions httpx/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from contextlib import contextmanager

from ._client import Client
from ._config import DEFAULT_TIMEOUT_CONFIG
from ._config import DEFAULT_TIMEOUT_CONFIG, SSLContext
from ._models import Response
from ._types import (
AuthTypes,
CertTypes,
CookieTypes,
HeaderTypes,
ProxiesTypes,
Expand All @@ -17,7 +16,6 @@
RequestFiles,
TimeoutTypes,
URLTypes,
VerifyTypes,
)


Expand All @@ -37,8 +35,7 @@ def request(
proxies: typing.Optional[ProxiesTypes] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
follow_redirects: bool = False,
verify: VerifyTypes = True,
cert: typing.Optional[CertTypes] = None,
ssl_context: typing.Optional[SSLContext] = None,
trust_env: bool = True,
) -> Response:
"""
Expand Down Expand Up @@ -70,14 +67,8 @@ def request(
* **timeout** - *(optional)* The timeout configuration to use when sending
the request.
* **follow_redirects** - *(optional)* Enables or disables HTTP redirects.
* **verify** - *(optional)* SSL certificates (a.k.a CA bundle) used to
verify the identity of requested hosts. Either `True` (default CA bundle),
a path to an SSL certificate file, an `ssl.SSLContext`, or `False`
(which will disable verification).
* **cert** - *(optional)* An SSL certificate used by the requested host
to authenticate the client. Either a path to an SSL certificate file, or
two-tuple of (certificate file, key file), or a three-tuple of (certificate
file, key file, password).
* **ssl_context** - *(optional)* An SSL certificate used by the requested host
to authenticate the client.
* **trust_env** - *(optional)* Enables or disables usage of environment
variables for configuration.

Expand All @@ -96,8 +87,7 @@ def request(
cookies=cookies,
proxy=proxy,
proxies=proxies,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
) as client:
Expand Down Expand Up @@ -132,8 +122,7 @@ def stream(
proxies: typing.Optional[ProxiesTypes] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
follow_redirects: bool = False,
verify: VerifyTypes = True,
cert: typing.Optional[CertTypes] = None,
ssl_context: typing.Optional[SSLContext] = None,
trust_env: bool = True,
) -> typing.Iterator[Response]:
"""
Expand All @@ -150,8 +139,7 @@ def stream(
cookies=cookies,
proxy=proxy,
proxies=proxies,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
) as client:
Expand Down Expand Up @@ -180,8 +168,7 @@ def get(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
ssl_context: typing.Optional[SSLContext] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
trust_env: bool = True,
) -> Response:
Expand All @@ -203,8 +190,7 @@ def get(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Expand All @@ -220,8 +206,7 @@ def options(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
ssl_context: typing.Optional[SSLContext] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
trust_env: bool = True,
) -> Response:
Expand All @@ -243,8 +228,7 @@ def options(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Expand All @@ -260,8 +244,7 @@ def head(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
ssl_context: typing.Optional[SSLContext] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
trust_env: bool = True,
) -> Response:
Expand All @@ -283,8 +266,7 @@ def head(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Expand All @@ -304,8 +286,7 @@ def post(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
ssl_context: typing.Optional[SSLContext] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
trust_env: bool = True,
) -> Response:
Expand All @@ -328,8 +309,7 @@ def post(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Expand All @@ -349,8 +329,7 @@ def put(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
ssl_context: typing.Optional[SSLContext] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
trust_env: bool = True,
) -> Response:
Expand All @@ -373,8 +352,7 @@ def put(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Expand All @@ -394,8 +372,7 @@ def patch(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
ssl_context: typing.Optional[SSLContext] = None,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
trust_env: bool = True,
) -> Response:
Expand All @@ -418,8 +395,7 @@ def patch(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Expand All @@ -435,9 +411,8 @@ def delete(
proxy: typing.Optional[ProxyTypes] = None,
proxies: typing.Optional[ProxiesTypes] = None,
follow_redirects: bool = False,
cert: typing.Optional[CertTypes] = None,
verify: VerifyTypes = True,
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
ssl_context: typing.Optional[SSLContext] = None,
trust_env: bool = True,
) -> Response:
"""
Expand All @@ -458,8 +433,7 @@ def delete(
proxy=proxy,
proxies=proxies,
follow_redirects=follow_redirects,
cert=cert,
verify=verify,
ssl_context=ssl_context,
timeout=timeout,
trust_env=trust_env,
)
Loading