Skip to content

Commit

Permalink
improve self-connect error message (#5192)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils committed Mar 17, 2022
1 parent 3a5550a commit a9283be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion mitmproxy/addons/proxyserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async def refresh_server(self):
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)}")

Expand Down Expand Up @@ -208,4 +209,7 @@ def server_connect(self, ctx: server_hooks.ServerConnectionHookData):
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."
)
2 changes: 1 addition & 1 deletion test/mitmproxy/addons/test_proxyserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit a9283be

Please sign in to comment.