aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.travis.yml14
-rw-r--r--README1
-rw-r--r--netlib/http.py4
-rw-r--r--netlib/http_auth.py2
-rw-r--r--netlib/tcp.py9
-rw-r--r--netlib/test.py9
-rw-r--r--requirements.txt4
-rw-r--r--test/test_tcp.py12
8 files changed, 46 insertions, 9 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..7e4209c0
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,14 @@
+language: python
+python:
+ - "2.7"
+# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
+install:
+ - "pip install coveralls --use-mirrors"
+ - "pip install nose-cov --use-mirrors"
+ - "pip install -r requirements.txt --use-mirrors"
+ - "pip install --upgrade git+https://github.com/mitmproxy/pathod.git"
+# command to run tests, e.g. python setup.py test
+script:
+ - "nosetests --with-cov --cov-report term-missing"
+after_success:
+ - coveralls \ No newline at end of file
diff --git a/README b/README
index 58a61c50..f3516faf 100644
--- a/README
+++ b/README
@@ -1,3 +1,4 @@
+[![Build Status](https://travis-ci.org/mitmproxy/netlib.png)](https://travis-ci.org/mitmproxy/netlib) [![Coverage Status](https://coveralls.io/repos/mitmproxy/netlib/badge.png)](https://coveralls.io/r/mitmproxy/netlib)
Netlib is a collection of network utility classes, used by the pathod and
mitmproxy projects. It differs from other projects in some fundamental
diff --git a/netlib/http.py b/netlib/http.py
index 7060b688..e160bd79 100644
--- a/netlib/http.py
+++ b/netlib/http.py
@@ -233,6 +233,10 @@ def parse_init(line):
def parse_init_connect(line):
+ """
+ Returns (host, port, httpversion) if line is a valid CONNECT line.
+ http://tools.ietf.org/html/draft-luotonen-web-proxy-tunneling-01 section 3.1
+ """
v = parse_init(line)
if not v:
return None
diff --git a/netlib/http_auth.py b/netlib/http_auth.py
index 69bee5c1..8f062826 100644
--- a/netlib/http_auth.py
+++ b/netlib/http_auth.py
@@ -126,8 +126,6 @@ class AuthAction(Action):
"""
def __call__(self, parser, namespace, values, option_string=None):
passman = self.getPasswordManager(values)
- if not passman:
- raise ArgumentTypeError("Error creating password manager for proxy authentication.")
authenticator = BasicProxyAuth(passman, "mitmproxy")
setattr(namespace, self.dest, authenticator)
diff --git a/netlib/tcp.py b/netlib/tcp.py
index aa9ca027..33f7ef3a 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -178,11 +178,11 @@ class TCPClient:
wbufsize = -1
def __init__(self, host, port, source_address=None, use_ipv6=False):
self.host, self.port = host, port
+ self.source_address = source_address
+ self.use_ipv6 = use_ipv6
self.connection, self.rfile, self.wfile = None, None, None
self.cert = None
self.ssl_established = False
- self.source_address = source_address
- self.use_ipv6 = use_ipv6
def convert_to_ssl(self, cert=None, sni=None, method=TLSv1_METHOD, options=None):
"""
@@ -359,11 +359,12 @@ class BaseHandler:
class TCPServer:
request_queue_size = 20
- def __init__(self, server_address):
+ def __init__(self, server_address, use_ipv6=False):
self.server_address = server_address
+ self.use_ipv6 = use_ipv6
self.__is_shut_down = threading.Event()
self.__shutdown_request = False
- self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.socket = socket.socket(socket.AF_INET6 if self.use_ipv6 else socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind(self.server_address)
self.server_address = self.socket.getsockname()
diff --git a/netlib/test.py b/netlib/test.py
index e7d4c233..cd1a3847 100644
--- a/netlib/test.py
+++ b/netlib/test.py
@@ -16,6 +16,9 @@ class ServerThread(threading.Thread):
class ServerTestBase:
ssl = None
handler = None
+ addr = ("localhost", 0)
+ use_ipv6 = False
+
@classmethod
def setupAll(cls):
cls.q = Queue.Queue()
@@ -26,7 +29,7 @@ class ServerTestBase:
@classmethod
def makeserver(cls):
- return TServer(cls.ssl, cls.q, cls.handler)
+ return TServer(cls.ssl, cls.q, cls.handler, cls.addr, cls.use_ipv6)
@classmethod
def teardownAll(cls):
@@ -38,11 +41,11 @@ class ServerTestBase:
class TServer(tcp.TCPServer):
- def __init__(self, ssl, q, handler_klass, addr=("127.0.0.1", 0)):
+ def __init__(self, ssl, q, handler_klass, addr, use_ipv6):
"""
ssl: A {cert, key, v3_only} dict.
"""
- tcp.TCPServer.__init__(self, addr)
+ tcp.TCPServer.__init__(self, addr, use_ipv6=use_ipv6)
self.ssl, self.q = ssl, q
self.handler_klass = handler_klass
self.last_handler = None
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 00000000..ede8bf4a
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,4 @@
+pyasn1>=0.1.7
+pyOpenSSL>=0.13
+nose>=1.3.0
+pathod>=0.9.2 \ No newline at end of file
diff --git a/test/test_tcp.py b/test/test_tcp.py
index 220ece15..75dcad13 100644
--- a/test/test_tcp.py
+++ b/test/test_tcp.py
@@ -74,6 +74,18 @@ class TestServer(test.ServerTestBase):
assert c.rfile.readline() == testval
+class TestServerIPv6(test.ServerTestBase):
+ handler = EchoHandler
+ use_ipv6 = True
+
+ def test_echo(self):
+ testval = "echo!\n"
+ c = tcp.TCPClient("::1", self.port, use_ipv6=True)
+ c.connect()
+ c.wfile.write(testval)
+ c.wfile.flush()
+ assert c.rfile.readline() == testval
+
class FinishFailHandler(tcp.BaseHandler):
def handle(self):