mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 10:26:23 +00:00
0c6663d0d5
- Add an options parameter to the start() event. This is to be used by addons on startup to add custom options. - Add a running() event that is called once the proxy is up and running. - With the new paradigm we can't log during master __init__, so add a tiny termstatus addon to print proxy status to terminal once we're running.
30 lines
743 B
Python
30 lines
743 B
Python
"""
|
|
This script how to generate a mitmproxy dump file,
|
|
as it would also be generated by passing `-w` to mitmproxy.
|
|
In contrast to `-w`, this gives you full control over which
|
|
flows should be saved and also allows you to rotate files or log
|
|
to multiple files in parallel.
|
|
"""
|
|
import random
|
|
import sys
|
|
from mitmproxy import io
|
|
|
|
|
|
class Writer:
|
|
def __init__(self, path):
|
|
if path == "-":
|
|
f = sys.stdout
|
|
else:
|
|
f = open(path, "wb")
|
|
self.w = io.FlowWriter(f)
|
|
|
|
def response(self, flow):
|
|
if random.choice([True, False]):
|
|
self.w.add(flow)
|
|
|
|
|
|
def start(opts):
|
|
if len(sys.argv) != 2:
|
|
raise ValueError('Usage: -s "flowriter.py filename"')
|
|
return Writer(sys.argv[1])
|