improve self-connect error message (#5192)

This commit is contained in:
Maximilian Hils 2022-03-17 15:24:42 +01:00 committed by GitHub
parent 3a5550a09c
commit a9283befad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -140,6 +140,7 @@ class Proxyserver:
except OSError as e: except OSError as e:
ctx.log.error(str(e)) ctx.log.error(str(e))
return 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} 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)}") 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) ctx.server.address[0] in ("localhost", "127.0.0.1", "::1", self.options.listen_host)
) )
if self_connect: 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."
)

View File

@ -171,7 +171,7 @@ def test_self_connect():
ps.server_connect( ps.server_connect(
server_hooks.ServerConnectionHookData(server, client) 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(): def test_options():