From b39ea74bb6e0bf057c6bf6ac1b0beb3afa37e02b Mon Sep 17 00:00:00 2001 From: michaeljau Date: Wed, 7 Jan 2015 22:20:05 +0800 Subject: [PATCH 1/4] Update inlinescripts.html I updated the certutils.SSLCert reference from "libmproxy.certutils.SSLCert" to "netlib.certutils.SSLCert". --- doc-src/scripting/inlinescripts.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc-src/scripting/inlinescripts.html b/doc-src/scripting/inlinescripts.html index 2c3e0d6fd..7f05eedfe 100644 --- a/doc-src/scripting/inlinescripts.html +++ b/doc-src/scripting/inlinescripts.html @@ -130,7 +130,7 @@ The main classes you will deal with in writing mitmproxy scripts are: - libmproxy.certutils.SSLCert + netlib.certutils.SSLCert Exposes information SSL certificates. @@ -174,4 +174,4 @@ matching events will be skipped. ## Spaces in the script path By default, spaces are interpreted as separator between the inline script and its arguments (e.g. -s "foo.py 42"). Consequently, the script path needs to be wrapped in a separate pair of quotes if it contains spaces: --s "'./foo bar/baz.py' 42". \ No newline at end of file +-s "'./foo bar/baz.py' 42". From 3dcba41d6d1f9c2d4307978b1176fe990d10bc5a Mon Sep 17 00:00:00 2001 From: Nick HS Date: Thu, 8 Jan 2015 13:56:19 -0500 Subject: [PATCH 2/4] Error to stdout when loading bad replays from the command line --- libmproxy/console/__init__.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index f5b6a2a60..1e7f8403d 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -508,14 +508,22 @@ class ConsoleMaster(flow.FlowMaster): def client_playback_path(self, path): err, ret = self._readflow(path) if err: - self.statusbar.message(ret) + if not self.statusbar: + print >> sys.stderr, ret + sys.exit(1) + else: + self.statusbar.message(ret) else: self.start_client_playback(ret, False) def server_playback_path(self, path): err, ret = self._readflow(path) if err: - self.statusbar.message(ret) + if not self.statusbar: + print >> sys.stderr, ret + sys.exit(1) + else: + self.statusbar.message(ret) else: self.start_server_playback( ret, From 8af26bd0b7bbde32a95ce937afc178e75c51da71 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 9 Jan 2015 16:40:26 +0100 Subject: [PATCH 3/4] fix #443 --- libmproxy/console/__init__.py | 4 ++-- libmproxy/controller.py | 2 +- libmproxy/flow.py | 2 +- test/tools/bench.py | 24 ++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/tools/bench.py diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index f5b6a2a60..a8c728a9c 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -823,8 +823,8 @@ class ConsoleMaster(flow.FlowMaster): if changed: self.statusbar.redraw() size = self.drawscreen() - changed = self.tick(self.masterq, 0.01) - self.ui.set_input_timeouts(max_wait=0.01) + changed = self.tick(self.masterq, timeout=0.1) + self.ui.set_input_timeouts(max_wait=0) keys = self.ui.get_input() if keys: changed = True diff --git a/libmproxy/controller.py b/libmproxy/controller.py index 39e7695fa..980ff8c0d 100644 --- a/libmproxy/controller.py +++ b/libmproxy/controller.py @@ -108,7 +108,7 @@ class Master(object): self.should_exit.clear() self.server.start_slave(Slave, Channel(self.masterq, self.should_exit)) while not self.should_exit.is_set(): - self.tick(self.masterq, 0.01) + self.tick(self.masterq, 0.1) self.shutdown() def handle(self, mtype, obj): diff --git a/libmproxy/flow.py b/libmproxy/flow.py index f3b138e27..97ebc572b 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -758,7 +758,7 @@ class FlowMaster(controller.Master): self.shutdown() self.client_playback.tick(self) - return controller.Master.tick(self, q, timeout) + return super(FlowMaster, self).tick(q, timeout) def duplicate_flow(self, f): return self.load_flow(f.copy()) diff --git a/test/tools/bench.py b/test/tools/bench.py new file mode 100644 index 000000000..1028f61d4 --- /dev/null +++ b/test/tools/bench.py @@ -0,0 +1,24 @@ +from __future__ import print_function +import requests, time + +n = 100 +url = "http://192.168.1.1/" +proxy = "http://192.168.1.115:8080/" + +start = time.time() +for _ in range(n): + requests.get(url, allow_redirects=False, proxies=dict(http=proxy)) + print(".", end="") +t_mitmproxy = time.time()-start + +print("\r\nTotal time with mitmproxy: {}".format(t_mitmproxy)) + + + +start = time.time() +for _ in range(n): + requests.get(url, allow_redirects=False) + print(".", end="") +t_without = time.time()-start + +print("\r\nTotal time without mitmproxy: {}".format(t_without)) \ No newline at end of file From e18294437c4629f26dc65e16a9252ef61a109284 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 9 Jan 2015 17:17:12 +0100 Subject: [PATCH 4/4] document choice of timeout value, refs #443 --- libmproxy/controller.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libmproxy/controller.py b/libmproxy/controller.py index 980ff8c0d..9ca89184f 100644 --- a/libmproxy/controller.py +++ b/libmproxy/controller.py @@ -108,6 +108,10 @@ class Master(object): self.should_exit.clear() self.server.start_slave(Slave, Channel(self.masterq, self.should_exit)) while not self.should_exit.is_set(): + + # Don't choose a very small timeout in Python 2: + # https://github.com/mitmproxy/mitmproxy/issues/443 + # TODO: Lower the timeout value if we move to Python 3. self.tick(self.masterq, 0.1) self.shutdown()