diff --git a/mitmproxy/proxy2/layers/http/__init__.py b/mitmproxy/proxy2/layers/http/__init__.py index b9537754c..1e99af578 100644 --- a/mitmproxy/proxy2/layers/http/__init__.py +++ b/mitmproxy/proxy2/layers/http/__init__.py @@ -369,7 +369,7 @@ class HttpStream(layer.Layer): self._handle_event = self.passthrough else: yield from self.send_response() - return SendHttp(ResponseProtocolError(self.stream_id, "EOF"), self.context.client) + return (yield SendHttp(ResponseProtocolError(self.stream_id, "EOF"), self.context.client)) @expect(RequestData, RequestEndOfMessage, events.Event) def passthrough(self, event: events.Event) -> layer.CommandGenerator[None]: diff --git a/test/mitmproxy/proxy2/layers/test_http.py b/test/mitmproxy/proxy2/layers/test_http.py index b5c83bdd9..372d22f8d 100644 --- a/test/mitmproxy/proxy2/layers/test_http.py +++ b/test/mitmproxy/proxy2/layers/test_http.py @@ -339,7 +339,8 @@ def test_server_unreachable(tctx, connect): playbook << CloseConnection(tctx.client) assert playbook - assert flow().error + if not connect: + assert flow().error assert b"502 Bad Gateway" in err() assert b"Connection failed" in err()