aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2013-02-24 10:51:14 +1300
committerAldo Cortesi <aldo@nullcube.com>2013-02-24 10:51:14 +1300
commit51de9f9fdf6ec4cd345e0b2c8607453cc22c5045 (patch)
tree693493dda9a4982e0ab0e546fe0520930341f0d8
parent05e4d4468ec372adb73649e6980c525a185e9c07 (diff)
downloadmitmproxy-51de9f9fdf6ec4cd345e0b2c8607453cc22c5045.tar.gz
mitmproxy-51de9f9fdf6ec4cd345e0b2c8607453cc22c5045.tar.bz2
mitmproxy-51de9f9fdf6ec4cd345e0b2c8607453cc22c5045.zip
Test client connection close conditions.
-rw-r--r--test/test_server.py16
-rw-r--r--test/tservers.py3
2 files changed, 19 insertions, 0 deletions
diff --git a/test/test_server.py b/test/test_server.py
index 8aefa4b8..a2c65275 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -81,6 +81,22 @@ class TestHTTP(tservers.HTTPProxTest, SanityMixin):
assert "host" in l.request.headers
assert l.response.code == 304
+ def test_connection_close(self):
+ # Add a body, so we have a content-length header, which combined with
+ # HTTP1.1 means the connection is kept alive.
+ response = '%s/p/200:b@1'%self.urlbase
+
+ # Lets sanity check that the connection does indeed stay open by
+ # issuing two requests over the same connection
+ p = self.pathoc()
+ assert p.request("get:'%s'"%response)
+ assert p.request("get:'%s'"%response)
+
+ # Now check that the connection is closed as the client specifies
+ p = self.pathoc()
+ assert p.request("get:'%s':h'Connection'='close'"%response)
+ tutils.raises("disconnect", p.request, "get:'%s'"%response)
+
class TestHTTPS(tservers.HTTPProxTest, SanityMixin):
ssl = True
diff --git a/test/tservers.py b/test/tservers.py
index 3fdb8d13..ae0bacf5 100644
--- a/test/tservers.py
+++ b/test/tservers.py
@@ -117,6 +117,9 @@ class HTTPProxTest(ProxTestBase):
return d
def pathoc(self, connect_to = None):
+ """
+ Returns a connected Pathoc instance.
+ """
p = libpathod.pathoc.Pathoc("localhost", self.proxy.port)
p.connect(connect_to)
return p