aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-24 11:39:49 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-24 11:41:18 +1200
commit91752990d5863526745e5c31cfb4b7459d11047e (patch)
tree5309c036f76f78aac3056ed98935f0f766379994 /test
parenteb88cea3c74a253d3a08d010bfd328aa845c6d5b (diff)
downloadmitmproxy-91752990d5863526745e5c31cfb4b7459d11047e.tar.gz
mitmproxy-91752990d5863526745e5c31cfb4b7459d11047e.tar.bz2
mitmproxy-91752990d5863526745e5c31cfb4b7459d11047e.zip
Handle HTTP responses that have a body but no content-length or transfer encoding
We check if the server sent a connection:close header, and read till the socket closes. Closes #2
Diffstat (limited to 'test')
-rw-r--r--test/test_http.py23
-rw-r--r--test/test_tcp.py6
2 files changed, 28 insertions, 1 deletions
diff --git a/test/test_http.py b/test/test_http.py
index 0174a4aa..0b83e65a 100644
--- a/test/test_http.py
+++ b/test/test_http.py
@@ -64,7 +64,28 @@ def test_read_http_body_response():
h = odict.ODictCaseless()
h["content-length"] = [7]
s = cStringIO.StringIO("testing")
- assert http.read_http_body_response(s, h, False, None) == "testing"
+ assert http.read_http_body_response(s, h, None) == "testing"
+
+
+ h = odict.ODictCaseless()
+ s = cStringIO.StringIO("testing")
+ assert not http.read_http_body_response(s, h, None)
+
+ h = odict.ODictCaseless()
+ h["connection"] = ["close"]
+ s = cStringIO.StringIO("testing")
+ assert http.read_http_body_response(s, h, None) == "testing"
+
+
+def test_get_header_tokens():
+ h = odict.ODictCaseless()
+ assert http.get_header_tokens(h, "foo") == []
+ h["foo"] = ["bar"]
+ assert http.get_header_tokens(h, "foo") == ["bar"]
+ h["foo"] = ["bar, voing"]
+ assert http.get_header_tokens(h, "foo") == ["bar", "voing"]
+ h["foo"] = ["bar, voing", "oink"]
+ assert http.get_header_tokens(h, "foo") == ["bar", "voing", "oink"]
def test_read_http_body_request():
diff --git a/test/test_tcp.py b/test/test_tcp.py
index d6235b01..67c56a37 100644
--- a/test/test_tcp.py
+++ b/test/test_tcp.py
@@ -239,3 +239,9 @@ class TestFileLike:
s = cStringIO.StringIO("foobar\nfoobar")
s = tcp.FileLike(s)
assert s.readline(3) == "foo"
+
+ def test_limitless(self):
+ s = cStringIO.StringIO("f"*(50*1024))
+ s = tcp.FileLike(s)
+ ret = s.read(-1)
+ assert len(ret) == 50 * 1024