aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-03-02 22:42:36 +1300
committerAldo Cortesi <aldo@nullcube.com>2013-03-02 22:42:36 +1300
commitc20d1d7d32ea2ab1d1c4dd9a34724a8732c23338 (patch)
tree964c326ecb84ba8174abee4348ee1f63b1b0f931 /libmproxy/proxy.py
parent415844511c19b17743b42a5833590d1d683427d2 (diff)
downloadmitmproxy-c20d1d7d32ea2ab1d1c4dd9a34724a8732c23338.tar.gz
mitmproxy-c20d1d7d32ea2ab1d1c4dd9a34724a8732c23338.tar.bz2
mitmproxy-c20d1d7d32ea2ab1d1c4dd9a34724a8732c23338.zip
Extend unit tests for proxy.py to some tricky cases.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py46
1 files changed, 22 insertions, 24 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index a6a72d55..458ea2b5 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -326,11 +326,11 @@ class ProxyHandler(tcp.BaseHandler):
if not self.ssl_established and (port in self.config.transparent_proxy["sslports"]):
scheme = "https"
dummycert = self.find_cert(client_conn, host, port, host)
+ sni = HandleSNI(
+ self, client_conn, host, port,
+ dummycert, self.config.certfile or self.config.cacert
+ )
try:
- sni = HandleSNI(
- self, client_conn, host, port,
- dummycert, self.config.certfile or self.config.cacert
- )
self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
except tcp.NetLibError, v:
raise ProxyError(400, str(v))
@@ -356,31 +356,29 @@ class ProxyHandler(tcp.BaseHandler):
line = self.get_line(self.rfile)
if line == "":
return None
- if http.parse_init_connect(line):
- r = http.parse_init_connect(line)
- if not r:
- raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
- host, port, httpversion = r
-
- headers = self.read_headers(authenticate=True)
- self.wfile.write(
- 'HTTP/1.1 200 Connection established\r\n' +
- ('Proxy-agent: %s\r\n'%self.server_version) +
- '\r\n'
- )
- self.wfile.flush()
- dummycert = self.find_cert(client_conn, host, port, host)
- try:
+ if not self.proxy_connect_state:
+ connparts = http.parse_init_connect(line)
+ if connparts:
+ host, port, httpversion = connparts
+ headers = self.read_headers(authenticate=True)
+ self.wfile.write(
+ 'HTTP/1.1 200 Connection established\r\n' +
+ ('Proxy-agent: %s\r\n'%self.server_version) +
+ '\r\n'
+ )
+ self.wfile.flush()
+ dummycert = self.find_cert(client_conn, host, port, host)
sni = HandleSNI(
self, client_conn, host, port,
dummycert, self.config.certfile or self.config.cacert
)
- self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
- except tcp.NetLibError, v:
- raise ProxyError(400, str(v))
- self.proxy_connect_state = (host, port, httpversion)
- line = self.rfile.readline(line)
+ try:
+ self.convert_to_ssl(dummycert, self.config.certfile or self.config.cacert, handle_sni=sni)
+ except tcp.NetLibError, v:
+ raise ProxyError(400, str(v))
+ self.proxy_connect_state = (host, port, httpversion)
+ line = self.rfile.readline(line)
if self.proxy_connect_state:
r = http.parse_init_http(line)