diff --git a/httpcore/_async/connection.py b/httpcore/_async/connection.py index b42581df..878d7852 100644 --- a/httpcore/_async/connection.py +++ b/httpcore/_async/connection.py @@ -148,8 +148,9 @@ async def _connect(self, request: Request) -> AsyncNetworkStream: kwargs = { "ssl_context": ssl_context, - "server_hostname": sni_hostname - or self._origin.host.decode("ascii"), + "server_hostname": ( + sni_hostname or self._origin.host.decode("ascii") + ).rstrip("."), "timeout": timeout, } async with Trace("start_tls", logger, request, kwargs) as trace: diff --git a/httpcore/_async/http_proxy.py b/httpcore/_async/http_proxy.py index cc9d9206..6e2c2e9e 100644 --- a/httpcore/_async/http_proxy.py +++ b/httpcore/_async/http_proxy.py @@ -309,7 +309,7 @@ async def handle_async_request(self, request: Request) -> Response: kwargs = { "ssl_context": ssl_context, - "server_hostname": self._remote_origin.host.decode("ascii"), + "server_hostname": self._remote_origin.host.decode("ascii").rstrip("."), "timeout": timeout, } async with Trace("start_tls", logger, request, kwargs) as trace: diff --git a/httpcore/_async/socks_proxy.py b/httpcore/_async/socks_proxy.py index b363f55a..489dae1f 100644 --- a/httpcore/_async/socks_proxy.py +++ b/httpcore/_async/socks_proxy.py @@ -258,8 +258,9 @@ async def handle_async_request(self, request: Request) -> Response: kwargs = { "ssl_context": ssl_context, - "server_hostname": sni_hostname - or self._remote_origin.host.decode("ascii"), + "server_hostname": ( + sni_hostname or self._remote_origin.host.decode("ascii") + ).rstrip("."), "timeout": timeout, } async with Trace("start_tls", logger, request, kwargs) as trace: diff --git a/httpcore/_sync/connection.py b/httpcore/_sync/connection.py index 363f8be8..a5ac7a83 100644 --- a/httpcore/_sync/connection.py +++ b/httpcore/_sync/connection.py @@ -148,8 +148,9 @@ def _connect(self, request: Request) -> NetworkStream: kwargs = { "ssl_context": ssl_context, - "server_hostname": sni_hostname - or self._origin.host.decode("ascii"), + "server_hostname": ( + sni_hostname or self._origin.host.decode("ascii") + ).rstrip("."), "timeout": timeout, } with Trace("start_tls", logger, request, kwargs) as trace: diff --git a/httpcore/_sync/http_proxy.py b/httpcore/_sync/http_proxy.py index ecca88f7..924f4c58 100644 --- a/httpcore/_sync/http_proxy.py +++ b/httpcore/_sync/http_proxy.py @@ -309,7 +309,7 @@ def handle_request(self, request: Request) -> Response: kwargs = { "ssl_context": ssl_context, - "server_hostname": self._remote_origin.host.decode("ascii"), + "server_hostname": self._remote_origin.host.decode("ascii").rstrip("."), "timeout": timeout, } with Trace("start_tls", logger, request, kwargs) as trace: diff --git a/httpcore/_sync/socks_proxy.py b/httpcore/_sync/socks_proxy.py index 0ca96ddf..cfd52a0f 100644 --- a/httpcore/_sync/socks_proxy.py +++ b/httpcore/_sync/socks_proxy.py @@ -258,8 +258,9 @@ def handle_request(self, request: Request) -> Response: kwargs = { "ssl_context": ssl_context, - "server_hostname": sni_hostname - or self._remote_origin.host.decode("ascii"), + "server_hostname": ( + sni_hostname or self._remote_origin.host.decode("ascii") + ).rstrip("."), "timeout": timeout, } with Trace("start_tls", logger, request, kwargs) as trace: