HTTPS requests over HTTP proxy now work on either Python 2.4, 2.5 and 2.6+

This commit is contained in:
Bernardo Damele 2009-05-20 14:27:25 +00:00
parent 81d1a767ac
commit 93ee4a01e5

View File

@ -29,6 +29,12 @@ import socket
import urllib
import urllib2
from lib.core.settings import PYVERSION
if PYVERSION >= "2.6":
import ssl
class ProxyHTTPConnection(httplib.HTTPConnection):
_ports = {"http" : 80, "https" : 443}
@ -98,8 +104,12 @@ class ProxyHTTPSConnection(ProxyHTTPConnection):
ProxyHTTPConnection.connect(self)
# Make the sock ssl-aware
ssl = socket.ssl(self.sock, self.key_file, self.cert_file)
self.sock = httplib.FakeSocket(self.sock, ssl)
if PYVERSION >= "2.6":
sslobj = ssl.wrap_socket(self.sock, self.key_file, self.cert_file)
self.sock = sslobj
else:
sslobj = socket.ssl(self.sock, self.key_file, self.cert_file)
self.sock = httplib.FakeSocket(self.sock, sslobj)
class ProxyHTTPHandler(urllib2.HTTPHandler):