diff options
-rw-r--r-- | mitmproxy/console/common.py | 2 | ||||
-rw-r--r-- | mitmproxy/console/master.py | 3 | ||||
-rw-r--r-- | mitmproxy/console/options.py | 8 | ||||
-rw-r--r-- | mitmproxy/options.py | 5 | ||||
-rw-r--r-- | mitmproxy/web/app.py | 4 | ||||
-rw-r--r-- | test/mitmproxy/test_options.py | 14 |
6 files changed, 24 insertions, 12 deletions
diff --git a/mitmproxy/console/common.py b/mitmproxy/console/common.py index 470db88d..66962729 100644 --- a/mitmproxy/console/common.py +++ b/mitmproxy/console/common.py @@ -38,7 +38,7 @@ def is_keypress(k): """ Is this input event a keypress? """ - if isinstance(k, basestring): + if isinstance(k, six.string_types): return True diff --git a/mitmproxy/console/master.py b/mitmproxy/console/master.py index 8e5dae6b..605b0e23 100644 --- a/mitmproxy/console/master.py +++ b/mitmproxy/console/master.py @@ -295,9 +295,6 @@ class ConsoleMaster(flow.FlowMaster): self.__dict__[name] = value signals.update_settings.send(self) - def set_stickyauth(self, txt): - self.options.stickyauth = txt - def options_error(self, opts, exc): signals.status_message.send( message=str(exc), diff --git a/mitmproxy/console/options.py b/mitmproxy/console/options.py index 331c28a5..f6342814 100644 --- a/mitmproxy/console/options.py +++ b/mitmproxy/console/options.py @@ -153,7 +153,6 @@ class Options(urwid.WidgetWrap): def clearall(self): self.master.anticache = False - self.master.anticomp = False self.master.killextra = False self.master.showhost = False self.master.refresh_server_playback = True @@ -163,8 +162,11 @@ class Options(urwid.WidgetWrap): self.master.set_ignore_filter([]) self.master.set_tcp_filter([]) self.master.scripts = [] - self.master.set_stickyauth(None) self.master.set_stickycookie(None) + + self.master.options.stickyauth = None + self.master.options.anticomp = False + self.master.state.default_body_view = contentviews.get("Auto") signals.update_settings.send(self) @@ -263,7 +265,7 @@ class Options(urwid.WidgetWrap): signals.status_prompt.send( prompt = "Sticky auth filter", text = self.master.options.stickyauth, - callback = self.master.set_stickyauth + callback = self.master.options.setter("stickyauth") ) def sticky_cookie(self): diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 0cc5fee1..5599185d 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -65,5 +65,10 @@ class Options(object): self._opts.update(kwargs) self.changed.send(self) + def setter(self, attr): + if attr not in self._opts: + raise KeyError("No such option: %s" % attr) + return lambda x: self.__setattr__(attr, x) + def __repr__(self): return pprint.pformat(self._opts) diff --git a/mitmproxy/web/app.py b/mitmproxy/web/app.py index f9d0dca6..ad149270 100644 --- a/mitmproxy/web/app.py +++ b/mitmproxy/web/app.py @@ -344,7 +344,7 @@ class Settings(RequestHandler): http2=self.master.server.config.http2, anticache=self.master.options.anticache, anticomp=self.master.options.anticomp, - stickyauth=self.master.stickyauth_txt, + stickyauth=self.master.options.stickyauth, stickycookie=self.master.stickycookie_txt, stream= self.master.stream_large_bodies.max_size if self.master.stream_large_bodies else False ) @@ -378,7 +378,7 @@ class Settings(RequestHandler): self.master.set_stickycookie(v) update[k] = v elif k == "stickyauth": - self.master.set_stickyauth(v) + self.master.options.stickyauth = v update[k] = v elif k == "stream": self.master.set_stream_large_bodies(v) diff --git a/test/mitmproxy/test_options.py b/test/mitmproxy/test_options.py index 5fdb7abe..97db9430 100644 --- a/test/mitmproxy/test_options.py +++ b/test/mitmproxy/test_options.py @@ -3,7 +3,7 @@ import copy from mitmproxy import options from mitmproxy import exceptions -from netlib.tutils import raises +from netlib import tutils class TO(options.Options): @@ -19,8 +19,8 @@ def test_options(): assert o.two == "three" o.one = "one" assert o.one == "one" - raises("no such option", setattr, o, "nonexistent", "value") - raises("no such option", o.update, nonexistent = "value") + tutils.raises("no such option", setattr, o, "nonexistent", "value") + tutils.raises("no such option", o.update, nonexistent = "value") rec = [] @@ -38,6 +38,14 @@ def test_options(): assert rec[-1].one == "oink" +def test_setter(): + o = TO(two="three") + f = o.setter("two") + f("xxx") + assert o.two == "xxx" + tutils.raises("no such option", o.setter, "nonexistent") + + def test_rollback(): o = TO(one="two") |