diff --git a/mitmproxy/types/multidict.py b/mitmproxy/types/multidict.py index 31a1f22b7..ac49200b6 100644 --- a/mitmproxy/types/multidict.py +++ b/mitmproxy/types/multidict.py @@ -230,3 +230,6 @@ class MultiDictView(_MultiDict): @fields.setter def fields(self, value): self._setter(value) + + def copy(self): + return MultiDict(self.fields) diff --git a/test/mitmproxy/types/test_multidict.py b/test/mitmproxy/types/test_multidict.py index 9b13c5cd8..7d38f6ba6 100644 --- a/test/mitmproxy/types/test_multidict.py +++ b/test/mitmproxy/types/test_multidict.py @@ -205,3 +205,12 @@ class TestMultiDictView: tv["c"] = "b" assert p.vals == (("a", "b"), ("c", "b")) assert tv["a"] == "b" + + def test_copy(self): + p = TParent() + tv = multidict.MultiDictView(p.getter, p.setter) + c = tv.copy() + assert isinstance(c, multidict.MultiDict) + assert tv.items() == c.items() + c["foo"] = "bar" + assert tv.items() != c.items()