From c744ef2dcbb95182668ed8897542029c6c6734b9 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 5 Jan 2013 17:06:41 +1300 Subject: [PATCH] Proxy mode: drop to SSL if we see an HTTP CONNECT request --- libpathod/pathod.py | 14 ++++++++++++-- test/test_pathod.py | 4 ++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 48aa076f7..fa5d519cd 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -63,14 +63,24 @@ class PathodHandler(tcp.BaseHandler): m = utils.MemBool() if m(http.parse_init_connect(line)): + headers = http.read_headers(self.rfile) self.wfile.write( 'HTTP/1.1 200 Connection established\r\n' + ('Proxy-agent: %s\r\n'%version.NAMEVERSION) + '\r\n' ) self.wfile.flush() - - if m(http.parse_init_proxy(line)): + try: + self.convert_to_ssl( + self.server.ssloptions.certfile, + self.server.ssloptions.keyfile, + ) + except tcp.NetLibError, v: + s = str(v) + self.info(s) + return False, dict(type = "error", msg = s) + return True, None + elif m(http.parse_init_proxy(line)): method, _, _, _, path, httpversion = m.v elif m(http.parse_init_http(line)): method, path, httpversion = m.v diff --git a/test/test_pathod.py b/test/test_pathod.py index 072d56235..0936fce34 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -143,6 +143,10 @@ class CommonTests(tutils.DaemonTests): assert rsp.status_code == 800 assert "File access denied" in rsp.content + def test_proxy(self): + v = self.pathoc(r"get:'http://foo.com/p/202':da") + assert v[1] == 202 + class TestDaemon(CommonTests): ssl = False