Use new TCPClient.convert_to_ssl API.

This commit is contained in:
Aldo Cortesi 2012-06-25 15:53:26 +12:00
parent e08f91c237
commit 52d0536d2c

View File

@ -50,8 +50,8 @@ class RequestReplayThread(threading.Thread):
def run(self): def run(self):
try: try:
r = self.flow.request r = self.flow.request
server = ServerConnection(self.config, r.scheme, r.host, r.port) server = ServerConnection(self.config, r.host, r.port)
server.connect() server.connect(r.scheme)
server.send(r) server.send(r)
httpversion, code, msg, headers, content = http.read_response( httpversion, code, msg, headers, content = http.read_response(
server.rfile, r.method, self.config.body_size_limit server.rfile, r.method, self.config.body_size_limit
@ -68,22 +68,21 @@ class RequestReplayThread(threading.Thread):
class ServerConnection(tcp.TCPClient): class ServerConnection(tcp.TCPClient):
def __init__(self, config, scheme, host, port): def __init__(self, config, host, port):
clientcert = None tcp.TCPClient.__init__(self, host, port)
if config.clientcerts: self.config = config
path = os.path.join(config.clientcerts, self.host) + ".pem"
if os.path.exists(clientcert):
clientcert = path
tcp.TCPClient.__init__(
self,
True if scheme == "https" else False,
host,
port,
clientcert
)
self.config, self.scheme = config, scheme
self.requestcount = 0 self.requestcount = 0
def connect(self, scheme):
tcp.TCPClient.connect(self)
if scheme == "https":
clientcert = None
if self.config.clientcerts:
path = os.path.join(self.config.clientcerts, self.host) + ".pem"
if os.path.exists(clientcert):
clientcert = path
self.convert_to_ssl(clientcert=clientcert)
def send(self, request): def send(self, request):
self.requestcount += 1 self.requestcount += 1
try: try:
@ -128,8 +127,8 @@ class ProxyHandler(tcp.BaseHandler):
self.server_conn = None self.server_conn = None
if not self.server_conn: if not self.server_conn:
try: try:
self.server_conn = ServerConnection(self.config, scheme, host, port) self.server_conn = ServerConnection(self.config, host, port)
self.server_conn.connect() self.server_conn.connect(scheme)
except tcp.NetLibError, v: except tcp.NetLibError, v:
raise ProxyError(502, v) raise ProxyError(502, v)