mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-02 02:37:15 +00:00
Allow no-op assignments to Server.address when connection open (#4687)
* Allow no-op assignments to Server.address when connection open * add explanatory comment in source Co-authored-by: Salad Dais <SaladDais@users.noreply.github.com> Co-authored-by: Maximilian Hils <github@maximilianhils.com>
This commit is contained in:
parent
95a9e4bdef
commit
2d866ce991
2 changed files with 8 additions and 2 deletions
|
|
@ -291,8 +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" and self.__dict__.get("state", ConnectionState.CLOSED) is ConnectionState.OPEN:
|
||||
raise RuntimeError("Cannot change server address on open connection.")
|
||||
if name == "address":
|
||||
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.")
|
||||
return super().__setattr__(name, value)
|
||||
|
||||
def get_state(self):
|
||||
|
|
|
|||
|
|
@ -85,3 +85,5 @@ class TestServer:
|
|||
s.state = ConnectionState.OPEN
|
||||
with pytest.raises(RuntimeError):
|
||||
s.address = ("example.com", 80)
|
||||
# No-op assignment, allowed because it might be triggered by a Server.set_state() call.
|
||||
s.address = ("example.com", 443)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue