aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/addons/replace.py10
-rw-r--r--mitmproxy/options.py8
-rw-r--r--mitmproxy/test/taddons.py7
-rw-r--r--test/mitmproxy/addons/test_replace.py10
4 files changed, 18 insertions, 17 deletions
diff --git a/mitmproxy/addons/replace.py b/mitmproxy/addons/replace.py
index 054264fa..5173254a 100644
--- a/mitmproxy/addons/replace.py
+++ b/mitmproxy/addons/replace.py
@@ -1,5 +1,6 @@
import os
import re
+import typing
from mitmproxy import exceptions
from mitmproxy import flowfilter
@@ -47,6 +48,15 @@ class Replace:
def __init__(self):
self.lst = []
+ def load(self, loader):
+ loader.add_option(
+ "replacements", typing.Sequence[str], [],
+ """
+ Replacement patterns of the form "/pattern/regex/replacement", where
+ the separator can be any character.
+ """
+ )
+
def configure(self, updated):
"""
.replacements is a list of tuples (fpat, rex, s):
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index 02ae9c0f..6db2b907 100644
--- a/mitmproxy/options.py
+++ b/mitmproxy/options.py
@@ -67,7 +67,6 @@ class Options(optmanager.OptManager):
view_filter = None # type: Optional[str]
# FIXME: Options that should be uncomplicated to migrate to addons
- replacements = None # type: Sequence[str]
rfile = None # type: Optional[str]
save_stream_file = None # type: Optional[str]
save_stream_filter = None # type: Optional[str]
@@ -106,13 +105,6 @@ class Options(optmanager.OptManager):
"Use the Host header to construct URLs for display."
)
self.add_option(
- "replacements", Sequence[str], [],
- """
- Replacement patterns of the form "/pattern/regex/replacement", where
- the separator can be any character.
- """
- )
- self.add_option(
"setheaders", Sequence[str], [],
"""
Header set pattern of the form "/pattern/header/value", where the
diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py
index 12fc0986..7efa2eaf 100644
--- a/mitmproxy/test/taddons.py
+++ b/mitmproxy/test/taddons.py
@@ -59,17 +59,16 @@ class context:
provides a number of helper methods for common testing scenarios.
"""
- def __init__(self, *addons, master=None, options=None):
+ def __init__(self, *addons, options=None):
options = options or mitmproxy.options.Options()
- self.master = master or RecordingMaster(
+ self.master = RecordingMaster(
options
)
self.options = self.master.options
self.wrapped = None
- loader = addonmanager.Loader(self.master)
for a in addons:
- self.master.addons.invoke_addon(a, "load", loader)
+ self.master.addons.register(a)
def ctx(self):
"""
diff --git a/test/mitmproxy/addons/test_replace.py b/test/mitmproxy/addons/test_replace.py
index 9002afb5..9c1f7f79 100644
--- a/test/mitmproxy/addons/test_replace.py
+++ b/test/mitmproxy/addons/test_replace.py
@@ -18,7 +18,7 @@ class TestReplace:
def test_configure(self):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(r, replacements=["one/two/three"])
with pytest.raises(Exception, match="Invalid filter pattern"):
tctx.configure(r, replacements=["/~b/two/three"])
@@ -28,7 +28,7 @@ class TestReplace:
def test_simple(self):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(
r,
replacements=[
@@ -48,7 +48,7 @@ class TestReplace:
def test_order(self):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tctx.configure(
r,
replacements=[
@@ -67,7 +67,7 @@ class TestReplace:
class TestReplaceFile:
def test_simple(self, tmpdir):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
tmpfile = tmpdir.join("replacement")
tmpfile.write("bar")
tctx.configure(
@@ -81,7 +81,7 @@ class TestReplaceFile:
def test_nonexistent(self, tmpdir):
r = replace.Replace()
- with taddons.context() as tctx:
+ with taddons.context(r) as tctx:
with pytest.raises(Exception, match="Invalid file path"):
tctx.configure(
r,