aboutsummaryrefslogtreecommitdiffstats
path: root/examples/flowwriter.py
blob: cb5ccb0dc4456f1f10c005d5d2370161ea23eb53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import random
import sys

from mitmproxy.flow import FlowWriter


def start(context):
    if len(sys.argv) != 2:
        raise ValueError('Usage: -s "flowriter.py filename"')

    if sys.argv[1] == "-":
        f = sys.stdout
    else:
        f = open(sys.argv[1], "wb")
    context.flow_writer = FlowWriter(f)


def response(context, flow):
    if random.choice([True, False]):
        context.flow_writer.add(flow)