diff options
author | Ujjwal Verma <ujjwalverma1111@gmail.com> | 2017-06-13 01:37:08 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-13 01:37:08 +0530 |
commit | 9da6cc4534af50e456c4bf93b5e4a2fc862d377c (patch) | |
tree | f9013a5d2e0efd4f939342a7ac7939bab2131ac8 | |
parent | 33252cb6bb21c57c20edb4ec42963291ec40e096 (diff) | |
parent | 6ca45856b4106300d4cfe5d41de5278a026d8317 (diff) | |
download | mitmproxy-9da6cc4534af50e456c4bf93b5e4a2fc862d377c.tar.gz mitmproxy-9da6cc4534af50e456c4bf93b5e4a2fc862d377c.tar.bz2 mitmproxy-9da6cc4534af50e456c4bf93b5e4a2fc862d377c.zip |
Merge pull request #2393 from ujjwal96/streaming-test
Test for streaming
-rw-r--r-- | test/mitmproxy/proxy/protocol/test_http1.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/mitmproxy/proxy/protocol/test_http1.py b/test/mitmproxy/proxy/protocol/test_http1.py index b642afb3..1eff8666 100644 --- a/test/mitmproxy/proxy/protocol/test_http1.py +++ b/test/mitmproxy/proxy/protocol/test_http1.py @@ -1,3 +1,7 @@ +from unittest import mock +import pytest + +from mitmproxy import exceptions from mitmproxy.test import tflow from mitmproxy.net.http import http1 from mitmproxy.net.tcp import TCPClient @@ -77,3 +81,36 @@ class TestHeadContentLength(tservers.HTTPProxyTest): """head:'%s/p/200:h"Content-Length"="42"'""" % self.server.urlbase ) assert resp.headers["Content-Length"] == "42" + + +class TestStreaming(tservers.HTTPProxyTest): + + @pytest.mark.parametrize('streaming', [True, False]) + def test_streaming(self, streaming): + + class Stream: + def requestheaders(self, f): + f.request.stream = streaming + + def responseheaders(self, f): + f.response.stream = streaming + + def assert_write(self, v): + if streaming: + assert len(v) <= 4096 + return self.o.write(v) + + self.master.addons.add(Stream()) + p = self.pathoc() + with p.connect(): + with mock.patch("mitmproxy.net.tcp.Writer.write", side_effect=assert_write, autospec=True): + # response with 10000 bytes + r = p.request("post:'%s/p/200:b@10000'" % self.server.urlbase) + assert len(r.content) == 10000 + + if streaming: + with pytest.raises(exceptions.HttpReadDisconnect): # as the assertion in assert_write fails + # request with 10000 bytes + p.request("post:'%s/p/200':b@10000" % self.server.urlbase) + else: + assert p.request("post:'%s/p/200':b@10000" % self.server.urlbase) |