Skip to content

Commit cd19fca

Browse files
committed
Merge pull request #67 from philiptzou/pull-request-https-timeout
TimeoutHTTPSConnection fixes
2 parents 9335ff7 + 51a7e34 commit cd19fca

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

superlance/timeoutconn.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from superlance.compat import httplib
22
import socket
3+
import ssl
4+
35

46
class TimeoutHTTPConnection(httplib.HTTPConnection):
57
"""A customised HTTPConnection allowing a per-connection
@@ -12,7 +14,7 @@ def connect(self):
1214

1315
e = "getaddrinfo returns an empty list"
1416
for res in socket.getaddrinfo(self.host, self.port,
15-
0, socket.SOCK_STREAM):
17+
0, socket.SOCK_STREAM):
1618
af, socktype, proto, canonname, sa = res
1719
try:
1820
self.sock = socket.socket(af, socktype, proto)
@@ -28,6 +30,7 @@ def connect(self):
2830
if not self.sock:
2931
raise socket.error(e)
3032

33+
3134
class TimeoutHTTPSConnection(httplib.HTTPSConnection):
3235
timeout = None
3336

@@ -36,7 +39,6 @@ def connect(self):
3639

3740
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3841
if self.timeout:
39-
self.sock.settimeout(self.timeout)
42+
sock.settimeout(self.timeout)
4043
sock.connect((self.host, self.port))
41-
ssl = socket.ssl(sock, self.key_file, self.cert_file)
42-
self.sock = httplib.FakeSocket(sock, ssl)
44+
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)

0 commit comments

Comments
 (0)