Skip to content

Commit 58f8742

Browse files
committed
refactor: MocketSSLSocket use proper ssl-context instead of urllib3
1 parent b660968 commit 58f8742

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

mocket/ssl/socket.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,23 @@ def unwrap(self) -> MocketSocket:
6262
return self._original_socket
6363

6464
@classmethod
65-
def _create(cls, sock: MocketSocket, *args: Any, **kwargs: Any) -> MocketSSLSocket:
65+
def _create(
66+
cls,
67+
sock: MocketSocket,
68+
ssl_context: ssl.SSLContext | None = None,
69+
server_hostname: str | None = None,
70+
*args: Any,
71+
**kwargs: Any,
72+
) -> MocketSSLSocket:
6673
ssl_socket = MocketSSLSocket()
6774
ssl_socket._original_socket = sock
75+
ssl_socket._true_socket = sock._true_socket
6876

69-
from mocket.urllib3 import true_ssl_wrap_socket
70-
71-
ssl_socket._true_socket = true_ssl_wrap_socket(
72-
sock._true_socket,
73-
**kwargs,
74-
)
77+
if ssl_context:
78+
ssl_socket._true_socket = ssl_context.wrap_socket(
79+
sock=ssl_socket._true_socket,
80+
server_hostname=server_hostname,
81+
)
7582

7683
ssl_socket._kwargs = kwargs
7784

0 commit comments

Comments
 (0)