diff --git a/.travis.yml b/.travis.yml index 2cc190302..80f989b94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ python: - "2.7" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - - "pip install --upgrade git+https://github.com/mitmproxy/netlib.git" + - "pip install --upgrade git+https://github.com/mitmproxy/netlib.git@tcp_proxy" - "pip install -r requirements.txt --use-mirrors" - "pip install -r test/requirements.txt --use-mirrors" # command to run tests, e.g. python setup.py test diff --git a/examples/libpathod_pathoc.py b/examples/libpathod_pathoc.py index ca53b08f7..cf94151b2 100644 --- a/examples/libpathod_pathoc.py +++ b/examples/libpathod_pathoc.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from libpathod import pathoc -p = pathoc.Pathoc("google.com", 80) +p = pathoc.Pathoc(("google.com", 80)) p.connect() print p.request("get:/") print p.request("get:/foo") diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 0769b43cb..32ae8441b 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -22,8 +22,8 @@ SSLVERSIONS = { } class Pathoc(tcp.TCPClient): - def __init__(self, host, port, ssl=None, sni=None, sslversion=1, clientcert=None): - tcp.TCPClient.__init__(self, host, port) + def __init__(self, address, ssl=None, sni=None, sslversion=1, clientcert=None): + tcp.TCPClient.__init__(self, address) self.settings = dict( staticdir = os.getcwd(), unconstrained_file_access = True, @@ -68,7 +68,7 @@ class Pathoc(tcp.TCPClient): language.FileAccessDenied. """ r = language.parse_request(self.settings, spec) - language.serve(r, self.wfile, self.settings, self.host) + language.serve(r, self.wfile, self.settings, self.address.host) self.wfile.flush() return Response(*http.read_response(self.rfile, r.method, None)) @@ -109,7 +109,7 @@ class Pathoc(tcp.TCPClient): return if explain: - r = r.freeze(self.settings, self.host) + r = r.freeze(self.settings, self.address.host) resp, req = None, None if showreq: @@ -117,7 +117,7 @@ class Pathoc(tcp.TCPClient): if showresp: self.rfile.start_log() try: - req = language.serve(r, self.wfile, self.settings, self.host) + req = language.serve(r, self.wfile, self.settings, self.address.host) self.wfile.flush() resp = http.read_response(self.rfile, r.method, None) except http.HttpError, v: diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 5433805f5..2d964ef57 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -21,7 +21,7 @@ class PathodHandler(tcp.BaseHandler): wbufsize = 0 sni = None def info(self, s): - logger.info("%s:%s: %s"%(self.client_address[0], self.client_address[1], str(s))) + logger.info("%s:%s: %s"%(self.address[0], self.address[1], str(s))) def handle_sni(self, connection): self.sni = connection.get_servername() @@ -118,7 +118,7 @@ class PathodHandler(tcp.BaseHandler): headers = headers.lst, httpversion = httpversion, sni = self.sni, - remote_address = self.client_address, + remote_address = self.address, clientcert = clientcert ) @@ -155,13 +155,13 @@ class PathodHandler(tcp.BaseHandler): return False, dict(type = "error", msg="Access denied: web interface disabled") else: self.info("app: %s %s"%(method, path)) - cc = wsgi.ClientConn(self.client_address) + cc = wsgi.ClientConn(self.address) req = wsgi.Request(cc, "http", method, path, headers, content) sn = self.connection.getsockname() a = wsgi.WSGIAdaptor( self.server.app, sn[0], - self.server.port, + self.server.address.port, version.NAMEVERSION ) a.serve(req, self.wfile) diff --git a/libpathod/test.py b/libpathod/test.py index cc858497d..11c623030 100644 --- a/libpathod/test.py +++ b/libpathod/test.py @@ -75,5 +75,5 @@ class _PaThread(threading.Thread): ssl = self.ssl, **self.daemonargs ) - self.q.put(self.server.port) + self.q.put(self.server.address.port) self.server.serve_forever() diff --git a/pathoc b/pathoc index de8ae948b..c553f68c5 100755 --- a/pathoc +++ b/pathoc @@ -129,8 +129,7 @@ if __name__ == "__main__": try: for i in range(args.repeat): p = pathoc.Pathoc( - args.host, - port, + (args.host, port), ssl=args.ssl, sni=args.sni, sslversion=args.sslversion, diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 7493b2e7f..d96a17288 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -27,8 +27,7 @@ class _TestDaemon: def test_info(self): c = pathoc.Pathoc( - "127.0.0.1", - self.d.port, + ("127.0.0.1", self.d.port), ssl = self.ssl ) c.connect() @@ -41,8 +40,7 @@ class TestDaemonSSL(_TestDaemon): ssloptions = pathod.SSLOptions(request_client_cert=True) def test_sni(self): c = pathoc.Pathoc( - "127.0.0.1", - self.d.port, + ("127.0.0.1", self.d.port), ssl = True, sni = "foobar.com" ) @@ -54,8 +52,7 @@ class TestDaemonSSL(_TestDaemon): def test_clientcert(self): c = pathoc.Pathoc( - "127.0.0.1", - self.d.port, + ("127.0.0.1", self.d.port), ssl = True, clientcert = tutils.test_data.path("data/clientcert/client.pem") ) @@ -69,7 +66,7 @@ class TestDaemonSSL(_TestDaemon): class TestDaemon(_TestDaemon): ssl = False def tval(self, requests, showreq=False, showresp=False, explain=False, hexdump=False, timeout=None, ignorecodes=None, ignoretimeout=None): - c = pathoc.Pathoc("127.0.0.1", self.d.port) + c = pathoc.Pathoc(("127.0.0.1", self.d.port)) c.connect() if timeout: c.settimeout(timeout) @@ -88,7 +85,7 @@ class TestDaemon(_TestDaemon): return s.getvalue() def test_ssl_error(self): - c = pathoc.Pathoc("127.0.0.1", self.d.port, ssl = True) + c = pathoc.Pathoc(("127.0.0.1", self.d.port), ssl = True) tutils.raises("ssl handshake", c.connect) def test_ignorecodes(self): @@ -135,7 +132,7 @@ class TestDaemon(_TestDaemon): def test_connect_fail(self): to = ("foobar", 80) - c = pathoc.Pathoc("127.0.0.1", self.d.port) + c = pathoc.Pathoc(("127.0.0.1", self.d.port)) c.rfile, c.wfile = cStringIO.StringIO(), cStringIO.StringIO() tutils.raises("connect failed", c.http_connect, to) c.rfile = cStringIO.StringIO( diff --git a/test/test_pathod.py b/test/test_pathod.py index 9cd90e94e..9ab6d66d4 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -120,7 +120,7 @@ class CommonTests(tutils.DaemonTests): assert rsp.status_code == 202 def test_invalid_first_line(self): - c = tcp.TCPClient("localhost", self.d.port) + c = tcp.TCPClient(("localhost", self.d.port)) c.connect() if self.ssl: c.convert_to_ssl() @@ -169,7 +169,7 @@ class TestDaemon(CommonTests): class TestDaemonSSL(CommonTests): ssl = True def test_ssl_conn_failure(self): - c = tcp.TCPClient("localhost", self.d.port) + c = tcp.TCPClient(("localhost", self.d.port)) c.rbufsize = 0 c.wbufsize = 0 c.connect() diff --git a/test/tutils.py b/test/tutils.py index 596490532..1baf16e26 100644 --- a/test/tutils.py +++ b/test/tutils.py @@ -50,7 +50,7 @@ class DaemonTests: def pathoc(self, spec, timeout=None, connect_to=None, ssl=None): if ssl is None: ssl = self.ssl - c = pathoc.Pathoc("localhost", self.d.port, ssl=ssl) + c = pathoc.Pathoc(("localhost", self.d.port), ssl=ssl) c.connect(connect_to) if timeout: c.settimeout(timeout)