adjust to signature changes in netlib.tcp
This commit is contained in:
parent
1b566869de
commit
b994fb5a27
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
3
pathoc
3
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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue