Flow.kill: don't depend on reply status.

In principle, a flow is killable as long as the connection handler is still
checking the error status of the flow.

This is patch 2/4 of the reply-ectomy.
This commit is contained in:
Robert Xiao 2022-02-03 04:29:04 -08:00 committed by Maximilian Hils
parent 4448550746
commit fd43ca19c4
2 changed files with 6 additions and 10 deletions

View File

@ -193,11 +193,7 @@ class Flow(stateobject.StateObject):
@property @property
def killable(self): def killable(self):
"""*Read-only:* `True` if this flow can be killed, `False` otherwise.""" """*Read-only:* `True` if this flow can be killed, `False` otherwise."""
return ( return not (self.error and self.error.msg == Error.KILLED_MESSAGE)
self.reply and
self.reply.state in {"start", "taken"} and
not (self.error and self.error.msg == Error.KILLED_MESSAGE)
)
def kill(self): def kill(self):
""" """

View File

@ -7,7 +7,6 @@ import pytest
from mitmproxy import flow from mitmproxy import flow
from mitmproxy import flowfilter from mitmproxy import flowfilter
from mitmproxy.exceptions import ControlException
from mitmproxy.http import Headers, Request, Response, HTTPFlow from mitmproxy.http import Headers, Request, Response, HTTPFlow
from mitmproxy.net.http.cookies import CookieAttrs from mitmproxy.net.http.cookies import CookieAttrs
from mitmproxy.test.tflow import tflow from mitmproxy.test.tflow import tflow
@ -704,10 +703,11 @@ class TestHTTPFlow:
def test_kill(self): def test_kill(self):
f = tflow() f = tflow()
with pytest.raises(ControlException): f.intercept()
f.intercept() f.resume()
f.resume() assert f.killable
f.kill() f.kill()
assert not f.killable
f = tflow() f = tflow()
f.intercept() f.intercept()