adjust to signature changes in netlib.tcp

This commit is contained in:
Maximilian Hils 2014-01-28 19:28:20 +01:00
parent 1b566869de
commit b994fb5a27
9 changed files with 22 additions and 26 deletions

View File

@ -3,7 +3,7 @@ python:
- "2.7" - "2.7"
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: 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 requirements.txt --use-mirrors"
- "pip install -r test/requirements.txt --use-mirrors" - "pip install -r test/requirements.txt --use-mirrors"
# command to run tests, e.g. python setup.py test # command to run tests, e.g. python setup.py test

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
from libpathod import pathoc from libpathod import pathoc
p = pathoc.Pathoc("google.com", 80) p = pathoc.Pathoc(("google.com", 80))
p.connect() p.connect()
print p.request("get:/") print p.request("get:/")
print p.request("get:/foo") print p.request("get:/foo")

View File

@ -22,8 +22,8 @@ SSLVERSIONS = {
} }
class Pathoc(tcp.TCPClient): class Pathoc(tcp.TCPClient):
def __init__(self, host, port, ssl=None, sni=None, sslversion=1, clientcert=None): def __init__(self, address, ssl=None, sni=None, sslversion=1, clientcert=None):
tcp.TCPClient.__init__(self, host, port) tcp.TCPClient.__init__(self, address)
self.settings = dict( self.settings = dict(
staticdir = os.getcwd(), staticdir = os.getcwd(),
unconstrained_file_access = True, unconstrained_file_access = True,
@ -68,7 +68,7 @@ class Pathoc(tcp.TCPClient):
language.FileAccessDenied. language.FileAccessDenied.
""" """
r = language.parse_request(self.settings, spec) 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() self.wfile.flush()
return Response(*http.read_response(self.rfile, r.method, None)) return Response(*http.read_response(self.rfile, r.method, None))
@ -109,7 +109,7 @@ class Pathoc(tcp.TCPClient):
return return
if explain: if explain:
r = r.freeze(self.settings, self.host) r = r.freeze(self.settings, self.address.host)
resp, req = None, None resp, req = None, None
if showreq: if showreq:
@ -117,7 +117,7 @@ class Pathoc(tcp.TCPClient):
if showresp: if showresp:
self.rfile.start_log() self.rfile.start_log()
try: 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() self.wfile.flush()
resp = http.read_response(self.rfile, r.method, None) resp = http.read_response(self.rfile, r.method, None)
except http.HttpError, v: except http.HttpError, v:

View File

@ -21,7 +21,7 @@ class PathodHandler(tcp.BaseHandler):
wbufsize = 0 wbufsize = 0
sni = None sni = None
def info(self, s): 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): def handle_sni(self, connection):
self.sni = connection.get_servername() self.sni = connection.get_servername()
@ -118,7 +118,7 @@ class PathodHandler(tcp.BaseHandler):
headers = headers.lst, headers = headers.lst,
httpversion = httpversion, httpversion = httpversion,
sni = self.sni, sni = self.sni,
remote_address = self.client_address, remote_address = self.address,
clientcert = clientcert clientcert = clientcert
) )
@ -155,13 +155,13 @@ class PathodHandler(tcp.BaseHandler):
return False, dict(type = "error", msg="Access denied: web interface disabled") return False, dict(type = "error", msg="Access denied: web interface disabled")
else: else:
self.info("app: %s %s"%(method, path)) 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) req = wsgi.Request(cc, "http", method, path, headers, content)
sn = self.connection.getsockname() sn = self.connection.getsockname()
a = wsgi.WSGIAdaptor( a = wsgi.WSGIAdaptor(
self.server.app, self.server.app,
sn[0], sn[0],
self.server.port, self.server.address.port,
version.NAMEVERSION version.NAMEVERSION
) )
a.serve(req, self.wfile) a.serve(req, self.wfile)

View File

@ -75,5 +75,5 @@ class _PaThread(threading.Thread):
ssl = self.ssl, ssl = self.ssl,
**self.daemonargs **self.daemonargs
) )
self.q.put(self.server.port) self.q.put(self.server.address.port)
self.server.serve_forever() self.server.serve_forever()

3
pathoc
View File

@ -129,8 +129,7 @@ if __name__ == "__main__":
try: try:
for i in range(args.repeat): for i in range(args.repeat):
p = pathoc.Pathoc( p = pathoc.Pathoc(
args.host, (args.host, port),
port,
ssl=args.ssl, ssl=args.ssl,
sni=args.sni, sni=args.sni,
sslversion=args.sslversion, sslversion=args.sslversion,

View File

@ -27,8 +27,7 @@ class _TestDaemon:
def test_info(self): def test_info(self):
c = pathoc.Pathoc( c = pathoc.Pathoc(
"127.0.0.1", ("127.0.0.1", self.d.port),
self.d.port,
ssl = self.ssl ssl = self.ssl
) )
c.connect() c.connect()
@ -41,8 +40,7 @@ class TestDaemonSSL(_TestDaemon):
ssloptions = pathod.SSLOptions(request_client_cert=True) ssloptions = pathod.SSLOptions(request_client_cert=True)
def test_sni(self): def test_sni(self):
c = pathoc.Pathoc( c = pathoc.Pathoc(
"127.0.0.1", ("127.0.0.1", self.d.port),
self.d.port,
ssl = True, ssl = True,
sni = "foobar.com" sni = "foobar.com"
) )
@ -54,8 +52,7 @@ class TestDaemonSSL(_TestDaemon):
def test_clientcert(self): def test_clientcert(self):
c = pathoc.Pathoc( c = pathoc.Pathoc(
"127.0.0.1", ("127.0.0.1", self.d.port),
self.d.port,
ssl = True, ssl = True,
clientcert = tutils.test_data.path("data/clientcert/client.pem") clientcert = tutils.test_data.path("data/clientcert/client.pem")
) )
@ -69,7 +66,7 @@ class TestDaemonSSL(_TestDaemon):
class TestDaemon(_TestDaemon): class TestDaemon(_TestDaemon):
ssl = False ssl = False
def tval(self, requests, showreq=False, showresp=False, explain=False, hexdump=False, timeout=None, ignorecodes=None, ignoretimeout=None): 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() c.connect()
if timeout: if timeout:
c.settimeout(timeout) c.settimeout(timeout)
@ -88,7 +85,7 @@ class TestDaemon(_TestDaemon):
return s.getvalue() return s.getvalue()
def test_ssl_error(self): 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) tutils.raises("ssl handshake", c.connect)
def test_ignorecodes(self): def test_ignorecodes(self):
@ -135,7 +132,7 @@ class TestDaemon(_TestDaemon):
def test_connect_fail(self): def test_connect_fail(self):
to = ("foobar", 80) 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() c.rfile, c.wfile = cStringIO.StringIO(), cStringIO.StringIO()
tutils.raises("connect failed", c.http_connect, to) tutils.raises("connect failed", c.http_connect, to)
c.rfile = cStringIO.StringIO( c.rfile = cStringIO.StringIO(

View File

@ -120,7 +120,7 @@ class CommonTests(tutils.DaemonTests):
assert rsp.status_code == 202 assert rsp.status_code == 202
def test_invalid_first_line(self): def test_invalid_first_line(self):
c = tcp.TCPClient("localhost", self.d.port) c = tcp.TCPClient(("localhost", self.d.port))
c.connect() c.connect()
if self.ssl: if self.ssl:
c.convert_to_ssl() c.convert_to_ssl()
@ -169,7 +169,7 @@ class TestDaemon(CommonTests):
class TestDaemonSSL(CommonTests): class TestDaemonSSL(CommonTests):
ssl = True ssl = True
def test_ssl_conn_failure(self): def test_ssl_conn_failure(self):
c = tcp.TCPClient("localhost", self.d.port) c = tcp.TCPClient(("localhost", self.d.port))
c.rbufsize = 0 c.rbufsize = 0
c.wbufsize = 0 c.wbufsize = 0
c.connect() c.connect()

View File

@ -50,7 +50,7 @@ class DaemonTests:
def pathoc(self, spec, timeout=None, connect_to=None, ssl=None): def pathoc(self, spec, timeout=None, connect_to=None, ssl=None):
if ssl is None: if ssl is None:
ssl = self.ssl 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) c.connect(connect_to)
if timeout: if timeout:
c.settimeout(timeout) c.settimeout(timeout)