mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 09:37:37 +00:00
don't allow server.via
change for live connections
This commit is contained in:
parent
3cb89069b9
commit
0f5b8c88af
@ -291,12 +291,12 @@ class Server(Connection):
|
||||
return f"Server({human.format_address(self.address)}, state={self.state.name.lower()}{tls_state}{local_port})"
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == "address":
|
||||
if name in ("address", "via"):
|
||||
connection_open = self.__dict__.get("state", ConnectionState.CLOSED) is ConnectionState.OPEN
|
||||
# assigning the current value is okay, that may be an artifact of calling .set_state().
|
||||
address_changed = self.__dict__.get("address") != value
|
||||
if connection_open and address_changed:
|
||||
raise RuntimeError("Cannot change server address on open connection.")
|
||||
attr_changed = self.__dict__.get(name) != value
|
||||
if connection_open and attr_changed:
|
||||
raise RuntimeError(f"Cannot change server.{name} on open connection.")
|
||||
return super().__setattr__(name, value)
|
||||
|
||||
def get_state(self):
|
||||
|
@ -706,10 +706,15 @@ def test_upstream_proxy(tctx, redirect, scheme):
|
||||
|
||||
assert playbook
|
||||
|
||||
if redirect == "change-proxy":
|
||||
assert server2().address == ("other-proxy", 1234)
|
||||
if redirect == "change-destination":
|
||||
assert flow().server_conn.address[0] == "other-server"
|
||||
else:
|
||||
assert server2().address == ("proxy", 8080)
|
||||
assert flow().server_conn.address[0] == "example.com"
|
||||
|
||||
if redirect == "change-proxy":
|
||||
assert server2().address == flow().server_conn.via.address == ("other-proxy", 1234)
|
||||
else:
|
||||
assert server2().address == flow().server_conn.via.address == ("proxy", 8080)
|
||||
|
||||
assert (
|
||||
playbook
|
||||
|
Loading…
Reference in New Issue
Block a user