mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
Options unification: streamfile
We now have one option to control this. If the path is prefixed with a "+" we append, otherwise we overwrite.
This commit is contained in:
parent
71a830c836
commit
9b1f40da37
@ -35,11 +35,13 @@ class StreamFile:
|
||||
if self.stream:
|
||||
self.done()
|
||||
if options.streamfile:
|
||||
if options.streamfile_append:
|
||||
if options.streamfile.startswith("+"):
|
||||
path = options.streamfile[1:]
|
||||
mode = "ab"
|
||||
else:
|
||||
path = options.streamfile
|
||||
mode = "wb"
|
||||
self.start_stream_to_path(options.streamfile, mode, self.filt)
|
||||
self.start_stream_to_path(path, mode, self.filt)
|
||||
|
||||
def tcp_start(self, flow):
|
||||
if self.stream:
|
||||
|
@ -142,8 +142,10 @@ class Options(optmanager.OptManager):
|
||||
"Log verbosity."
|
||||
)
|
||||
self.add_option("default_contentview", "auto", str)
|
||||
self.add_option("streamfile", None, Optional[str])
|
||||
self.add_option("streamfile_append", False, bool)
|
||||
self.add_option(
|
||||
"streamfile", None, Optional[str],
|
||||
help="Write flows to file. Prefix path with + to append."
|
||||
)
|
||||
self.add_option(
|
||||
"server_replay_ignore_content", False, bool,
|
||||
"Ignore request's content while searching for a saved flow to replay."
|
||||
|
@ -15,18 +15,6 @@ class ParseException(Exception):
|
||||
|
||||
|
||||
def get_common_options(args):
|
||||
if args.streamfile and args.streamfile[0] == args.rfile:
|
||||
if args.streamfile[1] == "wb":
|
||||
raise exceptions.OptionsError(
|
||||
"Cannot use '{}' for both reading and writing flows. "
|
||||
"Are you looking for --afile?".format(args.rfile)
|
||||
)
|
||||
else:
|
||||
raise exceptions.OptionsError(
|
||||
"Cannot use '{}' for both reading and appending flows. "
|
||||
"That would trigger an infinite loop."
|
||||
)
|
||||
|
||||
# Proxy config
|
||||
certs = []
|
||||
for i in args.certs or []:
|
||||
@ -96,8 +84,7 @@ def get_common_options(args):
|
||||
stickyauth=args.stickyauth,
|
||||
stream_large_bodies=args.stream_large_bodies,
|
||||
showhost=args.showhost,
|
||||
streamfile=args.streamfile[0] if args.streamfile else None,
|
||||
streamfile_append=True if args.streamfile and args.streamfile[1] == "a" else False,
|
||||
streamfile=args.streamfile,
|
||||
verbosity=args.verbose,
|
||||
server_replay_nopop=args.server_replay_nopop,
|
||||
server_replay_ignore_content=args.server_replay_ignore_content,
|
||||
@ -168,17 +155,7 @@ def basic_options(parser, opts):
|
||||
action="store_const", dest="verbose", const=3,
|
||||
help="Increase log verbosity."
|
||||
)
|
||||
streamfile = parser.add_mutually_exclusive_group()
|
||||
streamfile.add_argument(
|
||||
"-w", "--wfile",
|
||||
action="store", dest="streamfile", type=lambda f: (f, "w"),
|
||||
help="Write flows to file."
|
||||
)
|
||||
streamfile.add_argument(
|
||||
"-a", "--afile",
|
||||
action="store", dest="streamfile", type=lambda f: (f, "a"),
|
||||
help="Append flows to file."
|
||||
)
|
||||
opts.make_parser(parser, "streamfile")
|
||||
opts.make_parser(parser, "anticomp")
|
||||
opts.make_parser(parser, "body_size_limit", metavar="SIZE")
|
||||
opts.make_parser(parser, "stream_large_bodies")
|
||||
|
@ -59,7 +59,7 @@ def test_simple():
|
||||
tctx.configure(sa, streamfile=None)
|
||||
assert rd(p)[0].response
|
||||
|
||||
tctx.configure(sa, streamfile=p, streamfile_append=True)
|
||||
tctx.configure(sa, streamfile="+" + p)
|
||||
f = tflow.tflow()
|
||||
sa.request(f)
|
||||
tctx.configure(sa, streamfile=None)
|
||||
|
Loading…
Reference in New Issue
Block a user