From d0ee4d60d09c607a208ae1b190e619a4f106538e Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 5 Jan 2013 19:44:12 -0800 Subject: Unit tests and minor code refactoring for ServerConnection. --- libmproxy/proxy.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 370eca9a..2485a0c9 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -48,9 +48,9 @@ class ProxyConfig: self.reverse_proxy = reverse_proxy self.transparent_proxy = transparent_proxy self.authenticator = authenticator - self.certstore = certutils.CertStore(certdir) + class RequestReplayThread(threading.Thread): def __init__(self, config, flow, masterq): self.config, self.flow, self.masterq = config, flow, masterq @@ -86,7 +86,7 @@ class ServerConnection(tcp.TCPClient): clientcert = None if self.config.clientcerts: path = os.path.join(self.config.clientcerts, self.host) + ".pem" - if os.path.exists(clientcert): + if os.path.exists(path): clientcert = path try: self.convert_to_ssl(clientcert=clientcert, sni=self.host) @@ -95,10 +95,10 @@ class ServerConnection(tcp.TCPClient): def send(self, request): self.requestcount += 1 + d = request._assemble() + if not d: + raise ProxyError(502, "Cannot transmit an incomplete request.") try: - d = request._assemble() - if not d: - raise ProxyError(502, "Incomplete request could not not be readied for transmission.") self.wfile.write(d) self.wfile.flush() except socket.error, err: @@ -373,7 +373,7 @@ class ProxyHandler(tcp.BaseHandler): def send_response(self, response): d = response._assemble() if not d: - raise ProxyError(502, "Incomplete response could not not be readied for transmission.") + raise ProxyError(502, "Cannot transmit an incomplete response.") self.wfile.write(d) self.wfile.flush() -- cgit v1.2.3