diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2013-03-02 16:57:00 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2013-03-02 16:57:00 +1300 |
commit | 155710f9912f0a7370deab2bef6ad0a51ce47f2b (patch) | |
tree | 34993c7582e43fabe17500f752f935d3f83c80c0 /libpathod/pathoc.py | |
parent | 9167b9b8b6f9235f4d4c5c3cf838dd7927a10116 (diff) | |
download | mitmproxy-155710f9912f0a7370deab2bef6ad0a51ce47f2b.tar.gz mitmproxy-155710f9912f0a7370deab2bef6ad0a51ce47f2b.tar.bz2 mitmproxy-155710f9912f0a7370deab2bef6ad0a51ce47f2b.zip |
Improve robustness of proxy CONNECT, test coverage to 100%.
Diffstat (limited to 'libpathod/pathoc.py')
-rw-r--r-- | libpathod/pathoc.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 650aa42a..1540d817 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -11,6 +11,9 @@ class Response: self.httpversion, self.status_code, self.msg = httpversion, status_code, msg self.headers, self.content = headers, content + def __repr__(self): + return "Response(%s - %s)"%(self.status_code, self.msg) + class Pathoc(tcp.TCPClient): def __init__(self, host, port, ssl=None, sni=None, clientcert=None): @@ -28,8 +31,13 @@ class Pathoc(tcp.TCPClient): '\r\n' ) wfile.flush() - rfile.readline() - headers = http.read_headers(self.rfile) + l = rfile.readline() + if not l: + raise PathocError("Proxy CONNECT failed") + parsed = http.parse_response_line(l) + if not parsed[1] == 200: + raise PathocError("Proxy CONNECT failed: %s - %s"%(parsed[1], parsed[2])) + headers = http.read_headers(rfile) def connect(self, connect_to=None): """ |