mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-22 15:37:45 +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})"
|
return f"Server({human.format_address(self.address)}, state={self.state.name.lower()}{tls_state}{local_port})"
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
if name == "address":
|
if name in ("address", "via"):
|
||||||
connection_open = self.__dict__.get("state", ConnectionState.CLOSED) is ConnectionState.OPEN
|
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().
|
# assigning the current value is okay, that may be an artifact of calling .set_state().
|
||||||
address_changed = self.__dict__.get("address") != value
|
attr_changed = self.__dict__.get(name) != value
|
||||||
if connection_open and address_changed:
|
if connection_open and attr_changed:
|
||||||
raise RuntimeError("Cannot change server address on open connection.")
|
raise RuntimeError(f"Cannot change server.{name} on open connection.")
|
||||||
return super().__setattr__(name, value)
|
return super().__setattr__(name, value)
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
|
@ -706,10 +706,15 @@ def test_upstream_proxy(tctx, redirect, scheme):
|
|||||||
|
|
||||||
assert playbook
|
assert playbook
|
||||||
|
|
||||||
if redirect == "change-proxy":
|
if redirect == "change-destination":
|
||||||
assert server2().address == ("other-proxy", 1234)
|
assert flow().server_conn.address[0] == "other-server"
|
||||||
else:
|
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 (
|
assert (
|
||||||
playbook
|
playbook
|
||||||
|
Loading…
Reference in New Issue
Block a user