aboutsummaryrefslogtreecommitdiffstats
path: root/test/helper_tools/dumperview.py
blob: e17dc77bb4a969de841ed2ee745dd431a823c2ec (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import click

from mitmproxy.addons import dumper
from mitmproxy.test import tflow
from mitmproxy.test import taddons


def show(flow_detail, flows):
    d = dumper.Dumper()
    with taddons.context() as ctx:
        ctx.configure(d, flow_detail=flow_detail)
        for f in flows:
            ctx.cycle(d, f)


@click.group()
def cli():
    pass


@cli.command()
@click.option('--level', default=1, help='Detail level')
def tcp(level):
    f1 = tflow.ttcpflow(client_conn=True, server_conn=True)
    show(level, [f1])


@cli.command()
@click.option('--level', default=1, help='Detail level')
def large(level):
    f1 = tflow.tflow(client_conn=True, server_conn=True, resp=True)
    f1.response.headers["content-type"] = "text/html"
    f1.response.content = b"foo bar voing\n" * 100
    show(level, [f1])


@cli.command()
@click.option('--level', default=1, help='Detail level')
def small(level):
    f1 = tflow.tflow(client_conn=True, server_conn=True, resp=True)
    f1.response.headers["content-type"] = "text/html"
    f1.response.content = b"<html><body>Hello!</body></html>"

    f2 = tflow.tflow(client_conn=True, server_conn=True, err=True)

    show(
        level,
        [
            f1, f2,
        ]
    )


if __name__ == "__main__":
    cli()