From 0c3b6ee667f6a73ae3ebd84b68c09cbf092c509c Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 3 Sep 2014 17:33:08 +0200 Subject: fix IOError handling --- libmproxy/protocol/http.py | 2 +- test/test_server.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 658c08ed..efeed008 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -1054,7 +1054,7 @@ class HTTPHandler(ProtocolHandler): flow.live = None return True - except (HttpAuthenticationError, http.HttpError, proxy.ProxyError, tcp.NetLibError), e: + except (HttpAuthenticationError, http.HttpError, proxy.ProxyError, tcp.NetLibError, IOError), e: self.handle_error(e, flow) return False diff --git a/test/test_server.py b/test/test_server.py index a570f10f..3125c2f3 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -112,7 +112,10 @@ class TestHTTP(tservers.HTTPProxTest, CommonMixin, AppMixin): # Tests a difficult-to-trigger condition, where an IOError is raised # within our read loop. with mock.patch("libmproxy.protocol.http.HTTPRequest.from_stream") as m: - m.side_effect = IOError("error!") + def brk(f, *args, **kwargs): + f.o._sock.close() + raise IOError("error!") + m.side_effect = brk tutils.raises("server disconnect", self.pathod, "304") def test_get_connection_switching(self): -- cgit v1.2.3 From 4bdd1ed9675cef4e8a559cdde945a2899200e38d Mon Sep 17 00:00:00 2001 From: deployable Date: Thu, 4 Sep 2014 10:47:27 +0100 Subject: Add urwid stop prior to stack trace so exceptions are not cleared from screen --- libmproxy/console/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index 1325aae5..9d029610 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -599,6 +599,8 @@ class ConsoleMaster(flow.FlowMaster): try: self.ui.run_wrapper(self.loop) except Exception: + self.ui.stop() + sys.stdout.flush() print >> sys.stderr, traceback.format_exc() print >> sys.stderr, "mitmproxy has crashed!" print >> sys.stderr, "Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy" -- cgit v1.2.3 From 4781c565a97b37d3401f87cd40b1d2c0fccba9ce Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 4 Sep 2014 12:29:44 +0200 Subject: fix #344 --- libmproxy/protocol/http.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index efeed008..1da9caa6 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -638,11 +638,12 @@ class HTTPResponse(HTTPMessage): return f def __repr__(self): + size = utils.pretty_size(len(self.content)) if self.content else "content missing" return "".format( code=self.code, msg=self.msg, - contenttype=self.headers.get_first("content-type", "?"), - size=utils.pretty_size(len(self.content)) + contenttype=self.headers.get_first("content-type", "unknown content type"), + size=size ) @classmethod -- cgit v1.2.3 From 39fa579dd564823171f804c4307ab93db4d3b961 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 4 Sep 2014 14:15:49 +0200 Subject: remove outdated IOError test case (https://github.com/mitmproxy/netlib/commit/f5fdfd8a9f17e0fe213a9cf54acae84e4bc31462) --- libmproxy/protocol/http.py | 2 +- test/test_server.py | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 1da9caa6..9faa4946 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -1055,7 +1055,7 @@ class HTTPHandler(ProtocolHandler): flow.live = None return True - except (HttpAuthenticationError, http.HttpError, proxy.ProxyError, tcp.NetLibError, IOError), e: + except (HttpAuthenticationError, http.HttpError, proxy.ProxyError, tcp.NetLibError), e: self.handle_error(e, flow) return False diff --git a/test/test_server.py b/test/test_server.py index 3125c2f3..24d0ca5c 100644 --- a/test/test_server.py +++ b/test/test_server.py @@ -108,16 +108,6 @@ class TestHTTP(tservers.HTTPProxTest, CommonMixin, AppMixin): assert p.request(req) assert p.request(req) - def test_proxy_ioerror(self): - # Tests a difficult-to-trigger condition, where an IOError is raised - # within our read loop. - with mock.patch("libmproxy.protocol.http.HTTPRequest.from_stream") as m: - def brk(f, *args, **kwargs): - f.o._sock.close() - raise IOError("error!") - m.side_effect = brk - tutils.raises("server disconnect", self.pathod, "304") - def test_get_connection_switching(self): def switched(l): for i in l: -- cgit v1.2.3