Skip to content

Commit

Permalink
Merge pull request #67 from philiptzou/pull-request-https-timeout
Browse files Browse the repository at this point in the history
TimeoutHTTPSConnection fixes
  • Loading branch information
mnaberez committed Aug 23, 2015
2 parents 9335ff7 + 51a7e34 commit cd19fca
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions superlance/timeoutconn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from superlance.compat import httplib
import socket
import ssl


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

e = "getaddrinfo returns an empty list"
for res in socket.getaddrinfo(self.host, self.port,
0, socket.SOCK_STREAM):
0, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
self.sock = socket.socket(af, socktype, proto)
Expand All @@ -28,6 +30,7 @@ def connect(self):
if not self.sock:
raise socket.error(e)


class TimeoutHTTPSConnection(httplib.HTTPSConnection):
timeout = None

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

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.timeout:
self.sock.settimeout(self.timeout)
sock.settimeout(self.timeout)
sock.connect((self.host, self.port))
ssl = socket.ssl(sock, self.key_file, self.cert_file)
self.sock = httplib.FakeSocket(sock, ssl)
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)

0 comments on commit cd19fca

Please sign in to comment.