diff --git a/mitmproxy/addons/streamfile.py b/mitmproxy/addons/streamfile.py index 624297f2b..183d20366 100644 --- a/mitmproxy/addons/streamfile.py +++ b/mitmproxy/addons/streamfile.py @@ -22,12 +22,12 @@ class StreamFile: def configure(self, options, updated): # We're already streaming - stop the previous stream and restart - if "filtstr" in updated: - if options.filtstr: - self.filt = flowfilter.parse(options.filtstr) + if "streamfile_filter" in updated: + if options.streamfile_filter: + self.filt = flowfilter.parse(options.streamfile_filter) if not self.filt: raise exceptions.OptionsError( - "Invalid filter specification: %s" % options.filtstr + "Invalid filter specification: %s" % options.streamfile_filter ) else: self.filt = None diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 31d0b6932..9acdbc29e 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -160,6 +160,10 @@ class Options(optmanager.OptManager): "streamfile", Optional[str], None, "Write flows to file. Prefix path with + to append." ) + self.add_option( + "streamfile_filter", Optional[str], None, + "Filter which flows are written to file." + ) self.add_option( "server_replay_ignore_content", bool, False, "Ignore request's content while searching for a saved flow to replay." diff --git a/test/mitmproxy/addons/test_streamfile.py b/test/mitmproxy/addons/test_streamfile.py index 3f78521ce..bcb27c79b 100644 --- a/test/mitmproxy/addons/test_streamfile.py +++ b/test/mitmproxy/addons/test_streamfile.py @@ -15,10 +15,12 @@ def test_configure(tmpdir): with pytest.raises(exceptions.OptionsError): tctx.configure(sa, streamfile=str(tmpdir)) with pytest.raises(Exception, match="Invalid filter"): - tctx.configure(sa, streamfile=str(tmpdir.join("foo")), filtstr="~~") - tctx.configure(sa, filtstr="foo") + tctx.configure( + sa, streamfile=str(tmpdir.join("foo")), streamfile_filter="~~" + ) + tctx.configure(sa, streamfile_filter="foo") assert sa.filt - tctx.configure(sa, filtstr=None) + tctx.configure(sa, streamfile_filter=None) assert not sa.filt