From a9283befaddb4fa0a6961871c7df890bb778eb60 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 17 Mar 2022 15:24:42 +0100 Subject: [PATCH] improve self-connect error message (#5192) --- mitmproxy/addons/proxyserver.py | 6 +++++- test/mitmproxy/addons/test_proxyserver.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mitmproxy/addons/proxyserver.py b/mitmproxy/addons/proxyserver.py index 834f31c7c..db1ce43c8 100644 --- a/mitmproxy/addons/proxyserver.py +++ b/mitmproxy/addons/proxyserver.py @@ -140,6 +140,7 @@ class Proxyserver: except OSError as e: ctx.log.error(str(e)) return + # TODO: This is a bit confusing currently for `-p 0`. addrs = {f"http://{human.format_address(s.getsockname())}" for s in self.server.sockets} ctx.log.info(f"Proxy server listening at {' and '.join(addrs)}") @@ -208,4 +209,7 @@ class Proxyserver: ctx.server.address[0] in ("localhost", "127.0.0.1", "::1", self.options.listen_host) ) if self_connect: - ctx.server.error = "Stopped mitmproxy from recursively connecting to itself." + ctx.server.error = ( + "Request destination unknown. " + "Unable to figure out where this request should be forwarded to." + ) diff --git a/test/mitmproxy/addons/test_proxyserver.py b/test/mitmproxy/addons/test_proxyserver.py index 6581827a8..4f13f7e9d 100644 --- a/test/mitmproxy/addons/test_proxyserver.py +++ b/test/mitmproxy/addons/test_proxyserver.py @@ -171,7 +171,7 @@ def test_self_connect(): ps.server_connect( server_hooks.ServerConnectionHookData(server, client) ) - assert server.error == "Stopped mitmproxy from recursively connecting to itself." + assert "Request destination unknown" in server.error def test_options():