aboutsummaryrefslogtreecommitdiffstats
path: root/test/mitmproxy/addons/test_streambodies.py
blob: 426ec9ae020ea03bb5ec815924f3d235a81cefb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from mitmproxy import exceptions
from mitmproxy.test import tflow
from mitmproxy.test import taddons
from mitmproxy.addons import streambodies
import pytest


def test_simple():
    sa = streambodies.StreamBodies()
    with taddons.context() as tctx:
        with pytest.raises(exceptions.OptionsError):
            tctx.configure(sa, stream_large_bodies = "invalid")
        tctx.configure(sa, stream_large_bodies = "10")

        f = tflow.tflow()
        f.request.content = b""
        f.request.headers["Content-Length"] = "1024"
        assert not f.request.stream
        sa.requestheaders(f)
        assert f.request.stream

        f = tflow.tflow(resp=True)
        f.response.content = b""
        f.response.headers["Content-Length"] = "1024"
        assert not f.response.stream
        sa.responseheaders(f)
        assert f.response.stream

        f = tflow.tflow(resp=True)
        f.response.headers["content-length"] = "invalid"
        tctx.cycle(sa, f)

        tctx.configure(sa, stream_websockets = True)
        f = tflow.twebsocketflow()
        assert not f.stream
        sa.websocket_start(f)
        assert f.stream