Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f723c71

Browse files
committed
Issue 19509: Don't call match_hostname() twice in http.client.
1 parent c6d471d commit f723c71

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Lib/http/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,13 +1204,13 @@ def connect(self):
12041204
server_hostname = self.host if ssl.HAS_SNI else None
12051205
self.sock = self._context.wrap_socket(sock,
12061206
server_hostname=server_hostname)
1207-
try:
1208-
if self._check_hostname:
1207+
if not self._context.check_hostname and self._check_hostname:
1208+
try:
12091209
ssl.match_hostname(self.sock.getpeercert(), self.host)
1210-
except Exception:
1211-
self.sock.shutdown(socket.SHUT_RDWR)
1212-
self.sock.close()
1213-
raise
1210+
except Exception:
1211+
self.sock.shutdown(socket.SHUT_RDWR)
1212+
self.sock.close()
1213+
raise
12141214

12151215
__all__.append("HTTPSConnection")
12161216

0 commit comments

Comments
 (0)