mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 09:37:37 +00:00
08895e9ba6
- restructure examples (fix #4031) - remove example dependencies from setup.py, we do not need special dependencies for our supported addons. - unify how we generate docs from code - improve example docs
30 lines
750 B
Python
30 lines
750 B
Python
"""
|
|
Generate a mitmproxy dump file.
|
|
|
|
This script demonstrates 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, http
|
|
import typing # noqa
|
|
|
|
|
|
class Writer:
|
|
def __init__(self, path: str) -> None:
|
|
self.f: typing.IO[bytes] = open(path, "wb")
|
|
self.w = io.FlowWriter(self.f)
|
|
|
|
def response(self, flow: http.HTTPFlow) -> None:
|
|
if random.choice([True, False]):
|
|
self.w.add(flow)
|
|
|
|
def done(self):
|
|
self.f.close()
|
|
|
|
|
|
addons = [Writer(sys.argv[1])]
|