addons.streamfile -> addons.save

Options:

    streamfile -> save_stream_file
    streamfile_filter -> save_stream_filter
This commit is contained in:
Aldo Cortesi 2017-04-27 15:58:54 +12:00
parent 8c4810f606
commit b7afcb5dc2
9 changed files with 38 additions and 38 deletions

View File

@ -14,7 +14,7 @@ from mitmproxy.addons import setheaders
from mitmproxy.addons import stickyauth
from mitmproxy.addons import stickycookie
from mitmproxy.addons import streambodies
from mitmproxy.addons import streamfile
from mitmproxy.addons import save
from mitmproxy.addons import upstream_auth
@ -36,6 +36,6 @@ def default_addons():
stickyauth.StickyAuth(),
stickycookie.StickyCookie(),
streambodies.StreamBodies(),
streamfile.StreamFile(),
save.Save(),
upstream_auth.UpstreamAuth(),
]

View File

@ -6,7 +6,7 @@ from mitmproxy import io
from mitmproxy import ctx
class StreamFile:
class Save:
def __init__(self):
self.stream = None
self.filt = None
@ -23,24 +23,24 @@ class StreamFile:
def configure(self, updated):
# We're already streaming - stop the previous stream and restart
if "streamfile_filter" in updated:
if ctx.options.streamfile_filter:
self.filt = flowfilter.parse(ctx.options.streamfile_filter)
if "save_stream_filter" in updated:
if ctx.options.save_stream_filter:
self.filt = flowfilter.parse(ctx.options.save_stream_filter)
if not self.filt:
raise exceptions.OptionsError(
"Invalid filter specification: %s" % ctx.options.streamfile_filter
"Invalid filter specification: %s" % ctx.options.save_stream_filter
)
else:
self.filt = None
if "streamfile" in updated:
if "save_stream_file" in updated:
if self.stream:
self.done()
if ctx.options.streamfile:
if ctx.options.streamfile.startswith("+"):
path = ctx.options.streamfile[1:]
if ctx.options.save_stream_file:
if ctx.options.save_stream_file.startswith("+"):
path = ctx.options.save_stream_file[1:]
mode = "ab"
else:
path = ctx.options.streamfile
path = ctx.options.save_stream_file
mode = "wb"
self.start_stream_to_path(path, mode, self.filt)

View File

@ -159,11 +159,11 @@ class Options(optmanager.OptManager):
choices = [i.name.lower() for i in contentviews.views]
)
self.add_option(
"streamfile", Optional[str], None,
"Write flows to file. Prefix path with + to append."
"save_stream_file", Optional[str], None,
"Stream flows to file as they arrive. Prefix path with + to append."
)
self.add_option(
"streamfile_filter", Optional[str], None,
"save_stream_filter", Optional[str], None,
"Filter which flows are written to file."
)
self.add_option(

View File

@ -130,7 +130,7 @@ class context:
def command(self, func, *args):
"""
Invoke a command function within a command context, mimicing the actual command environment.
Invoke a command function with a list of string arguments within a command context, mimicing the actual command environment.
"""
cmd = command.Command(self.master.commands, "test.command", func)
return cmd.call(args)

View File

@ -66,7 +66,7 @@ def common_options(parser, opts):
opts.make_parser(parser, "scripts", metavar="SCRIPT", short="s")
opts.make_parser(parser, "stickycookie", metavar="FILTER")
opts.make_parser(parser, "stickyauth", metavar="FILTER")
opts.make_parser(parser, "streamfile", metavar="PATH", short="w")
opts.make_parser(parser, "save_stream_file", metavar="PATH", short="w")
opts.make_parser(parser, "anticomp")
# Proxy options
@ -128,7 +128,7 @@ def mitmdump(opts):
nargs="...",
help="""
Filter expression, equivalent to setting both the view_filter
and streamfile_filter options.
and save_stream_filter options.
"""
)
return parser

View File

@ -411,13 +411,13 @@ class FlowListBox(urwid.ListBox):
val = not self.master.options.console_order_reversed
self.master.options.console_order_reversed = val
elif key == "W":
if self.master.options.streamfile:
self.master.options.streamfile = None
if self.master.options.save_stream_file:
self.master.options.save_stream_file = None
else:
signals.status_prompt_path.send(
self,
prompt="Stream flows to",
callback= lambda path: self.master.options.update(streamfile=path)
callback= lambda path: self.master.options.update(save_stream_file=path)
)
else:
return urwid.ListBox.keypress(self, size, key)

View File

@ -251,8 +251,8 @@ class StatusBar(urwid.WidgetWrap):
r.append(("heading_key", "s"))
r.append("cripts:%s]" % len(self.master.options.scripts))
if self.master.options.streamfile:
r.append("[W:%s]" % self.master.options.streamfile)
if self.master.options.save_stream_file:
r.append("[W:%s]" % self.master.options.save_stream_file)
return r

View File

@ -127,7 +127,7 @@ def mitmdump(args=None): # pragma: no cover
v = " ".join(args.filter_args)
return dict(
view_filter = v,
streamfile_filter = v,
save_stream_filter = v,
)
return {}

View File

@ -6,21 +6,21 @@ from mitmproxy.test import tflow
from mitmproxy import io
from mitmproxy import exceptions
from mitmproxy import options
from mitmproxy.addons import streamfile
from mitmproxy.addons import save
def test_configure(tmpdir):
sa = streamfile.StreamFile()
sa = save.Save()
with taddons.context(options=options.Options()) as tctx:
with pytest.raises(exceptions.OptionsError):
tctx.configure(sa, streamfile=str(tmpdir))
tctx.configure(sa, save_stream_file=str(tmpdir))
with pytest.raises(Exception, match="Invalid filter"):
tctx.configure(
sa, streamfile=str(tmpdir.join("foo")), streamfile_filter="~~"
sa, save_stream_file=str(tmpdir.join("foo")), save_stream_filter="~~"
)
tctx.configure(sa, streamfile_filter="foo")
tctx.configure(sa, save_stream_filter="foo")
assert sa.filt
tctx.configure(sa, streamfile_filter=None)
tctx.configure(sa, save_stream_filter=None)
assert not sa.filt
@ -30,33 +30,33 @@ def rd(p):
def test_tcp(tmpdir):
sa = streamfile.StreamFile()
sa = save.Save()
with taddons.context() as tctx:
p = str(tmpdir.join("foo"))
tctx.configure(sa, streamfile=p)
tctx.configure(sa, save_stream_file=p)
tt = tflow.ttcpflow()
sa.tcp_start(tt)
sa.tcp_end(tt)
tctx.configure(sa, streamfile=None)
tctx.configure(sa, save_stream_file=None)
assert rd(p)
def test_simple(tmpdir):
sa = streamfile.StreamFile()
sa = save.Save()
with taddons.context() as tctx:
p = str(tmpdir.join("foo"))
tctx.configure(sa, streamfile=p)
tctx.configure(sa, save_stream_file=p)
f = tflow.tflow(resp=True)
sa.request(f)
sa.response(f)
tctx.configure(sa, streamfile=None)
tctx.configure(sa, save_stream_file=None)
assert rd(p)[0].response
tctx.configure(sa, streamfile="+" + p)
tctx.configure(sa, save_stream_file="+" + p)
f = tflow.tflow()
sa.request(f)
tctx.configure(sa, streamfile=None)
tctx.configure(sa, save_stream_file=None)
assert not rd(p)[1].response